How do I scale an Image in Flex to fit a Canvas? My code follows:
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="center"
width="100" height="100"
verticalGap="0" borderStyle="solid"
initialize="onLoad()"
horizontalScrollPolicy="off"
verticalScrollPolicy="off">
<mx:Canvas width="100%" height="100%" id="PictureBox" horizontalScrollPolicy="off"
verticalScrollPolicy="off" />
<mx:Label id="NameLabel" height="20%" width="100%"/>
<mx:Script>
<![CDATA[
private function onLoad():void
{
var image:SmoothImage = data.thumbnail;
image.percentHeight = 100;
image.percentWidth = 100;
this.PictureBox.addChild(image);
var sizeString:String = new String();
if ((data.fr.size / 1024) >= 512)
sizeString = "" + int((data.fr.size / 1024 / 1024) * 100)/100 + " MB";
else
sizeString = "" + int((data.fr.size / 1024) * 100)/100 + " KB";
this.NameLabel.text = data.name + " \n" + sizeString;
}
]]>
</mx:Script>
</mx:VBox>
I am trying to get the image:SmoothImage into PictureBox and scaling it down.
Note SmoothImage derives from Image.
you need to make sure you have set
image.scaleContent = true;
image.maintainAspectRatio = false;
That should scale the content to the size of the swf loader and distortin it so it fills the entire area of the Image component.
Here's a quick version of it working
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="center"
width="100" height="100"
verticalGap="0" borderStyle="solid"
initialize="onLoad()"
horizontalScrollPolicy="off"
verticalScrollPolicy="off">
<mx:Canvas width="100%" height="100%" id="PictureBox" horizontalScrollPolicy="off"
verticalScrollPolicy="off" />
<mx:Label id="NameLabel" height="20%" width="100%"/>
<mx:Script>
<![CDATA[
import mx.controls.Image;
private function onLoad():void
{
var image : Image = new Image()
image.source = "http://i.stackoverflow.com/Content/Img/stackoverflow-logo-250.png";
image.scaleContent = true;
image.maintainAspectRatio =false;
image.percentWidth = 100;
image.percentHeight = 100;
PictureBox.addChild(image);
}
]]>
</mx:Script>
</mx:VBox>
Related
I'm somewhat new to Flex and have encountered a problem with itemRenderer that I can't find the solution to. I've asked a coworker with plenty of flex experience, and I've tried searching the internet with no luck.
My problem is that I have a dataGrid in which each column uses an itemRenderer to display information, and for some reason this causes the user to be unable to select any of the dataGrid rows. I think it must have something to do with itemRenderer, because when I added a dummy column without an itemRenderer, I was able to highlight and select a row by clicking on that dummy column, but the others still did not work. I've tried comparing my code with code for other dataGrids with itemRenderers that do work, but I haven't been able to find any differences that would cause the problem that mine is giving me. Does anyone know why this would happen?
Thank you!
My dataGrid (I tried to only include what I think should be relevant just to keep things concise. If anyone thinks more information is needed, please let me know!):
<mx:DataGrid id="servicegridUI" left="10" right="10" top="10" bottom="85" selectable="true"
styleName="formDataGrid" variableRowHeight="true" toolTip="Double-click to view.">
<mx:columns>
<mx:DataGridColumn headerText="ID" dataField="ID" width="175">
<mx:itemRenderer>
<mx:Component>
<mx:HBox paddingBottom="3" height="70" paddingLeft="5" horizontalGap="1" paddingTop="2" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Text height="100%" width="100%" id="id" htmlText="" selectable="true" doubleClick="openDoc(event)" doubleClickEnabled="true"/>
<mx:Script>
<![CDATA[
var refId:String = "";
override public function set data(value:Object):void {
//variables for setting text are created here
id.htmlText = 'ID: ' + refId + '<br><font color="#666666">Service ID: ' + servId + '</font>';
id.htmlText +='<br><font color="#666666">Type and Specialty: ' + type + ' - ' + specialty + '</font>';
}
public function openDoc(event:MouseEvent):void {
//removed due to irrelevance
}
]]>
</mx:Script>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="Claimant" dataField="claimantHeader" width="125">
<mx:itemRenderer>
<mx:Component>
<mx:HBox paddingBottom="3" height="70" paddingLeft="5" horizontalGap="1" paddingTop="2" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Text height="100%" width="100%" id="claimant" htmlText="" selectable="true" doubleClick="openDoc(event)" doubleClickEnabled="true"/>
<mx:Script>
<![CDATA[
var refId:String = "";
override public function set data(value:Object):void {
//variables for setting text are created here
claimant.htmlText = 'Claim: ' + claim + '<br><font color="#666666">Name: '+ name +'</font>';
claimant.htmlText +='<br><font color="#666666">Date: '+ date+'</font>';
}
// Opens a new browser window and loads the file
public function openDoc(event:MouseEvent):void {
//removed due to irrelevance
}
]]>
</mx:Script>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="Status" dataField="statusHeader" width="70">
<mx:itemRenderer>
<mx:Component>
<mx:HBox paddingBottom="3" height="70" paddingLeft="5" horizontalGap="1" paddingTop="2" horizontalScrollPolicy="off" verticalScrollPolicy="off" >
<mx:Text height="100%" width="100%" id="status" htmlText="" selectable="true" doubleClick="openDoc(event)" doubleClickEnabled="true"/>
<mx:Script>
<![CDATA[
var refId:String = "";
override public function set data(value:Object):void {
//variables for setting text are created here
status.htmlText = 'Date: ' + refDate;
status.htmlText += '<br><font color="#666666">Status: ' + currStatus + '</font>';
}
// Opens a new browser window and loads the file
public function openDoc(event:MouseEvent):void {
//removed due to irrelevance
}
]]>
</mx:Script>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="lalala" dataField="serviceID" width="50"/><!---this is the dummy column that I created and is the only one that functions properly-->
</mx:columns>
</mx:DataGrid>
When you override set data function, you need to say
super.data = value;
It will fix your problem.
If you want to run the complete application, here is an example based on your code:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script><![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var myArrayCollection:ArrayCollection = new ArrayCollection([
{ID:"1",claimantHeader: "ClaimHeader1",statusHeader:"StatusHeader1", serviceID:"SID1" , servId:"1001", name:"Bikram Dangol", type:"Type 1",specialty:"Speciality 1", claim:"Claim 1", date:"12/06/2014", refDate:"11/06/2014", currStatus:"Active"},
{ID:"2",claimantHeader: "ClaimHeader2",statusHeader:"StatusHeader2", serviceID:"SID2", servId:"1002", name:"Anup Dangol", type:"Type 2",specialty:"Speciality 2", claim:"Claim 2", date:"12/07/2014", refDate:"11/07/2014", currStatus:"Inactive"},
{ID:"3",claimantHeader: "ClaimHeader3",statusHeader:"StatusHeader3", serviceID:"SID3", servId:"1003",name:"Lunish Yakami", type:"Type 3",specialty:"Speciality 3", claim:"Claim 3", date:"12/08/2014", refDate:"11/08/2014", currStatus:"OnHold"},
]);
]]></mx:Script>
<mx:DataGrid id="servicegridUI" left="10" right="10" top="10" bottom="85" selectable="true" dataProvider="{myArrayCollection}"
styleName="formDataGrid" variableRowHeight="true" toolTip="Double-click to view.">
<mx:columns>
<mx:DataGridColumn headerText="ID" dataField="ID" width="175">
<mx:itemRenderer>
<mx:Component>
<mx:HBox paddingBottom="3" height="70" paddingLeft="5" horizontalGap="1" paddingTop="2" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Text height="100%" width="100%" id="ID" htmlText="" selectable="true" doubleClick="openDoc(event)" doubleClickEnabled="true"/>
<mx:Script>
<![CDATA[
var refId:String = "";
override public function set data(value:Object):void {
super.data = value;
//variables for setting text are created here
ID.htmlText = 'ID: ' + refId + '<br><font color="#666666">Service ID: ' + data.servId + '</font>';
ID.htmlText +='<br><font color="#666666">Type and Specialty: ' + data.type + ' - ' + data.specialty + '</font>';
}
public function openDoc(event:MouseEvent):void {
//removed due to irrelevance
}
]]>
</mx:Script>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="Claimant" dataField="claimantHeader" width="125">
<mx:itemRenderer>
<mx:Component>
<mx:HBox paddingBottom="3" height="70" paddingLeft="5" horizontalGap="1" paddingTop="2" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Text height="100%" width="100%" id="claimant" htmlText="" selectable="true" doubleClick="openDoc(event)" doubleClickEnabled="true"/>
<mx:Script>
<![CDATA[
var refId:String = "";
override public function set data(value:Object):void {
super.data = value;
//variables for setting text are created here
claimant.htmlText = 'Claim: ' + data.claim + '<br><font color="#666666">Name: '+ data.name +'</font>';
claimant.htmlText +='<br><font color="#666666">Date: '+ data.date+'</font>';
}
// Opens a new browser window and loads the file
public function openDoc(event:MouseEvent):void {
//removed due to irrelevance
}
]]>
</mx:Script>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="Status" dataField="statusHeader" width="70">
<mx:itemRenderer>
<mx:Component>
<mx:HBox paddingBottom="3" height="70" paddingLeft="5" horizontalGap="1" paddingTop="2" horizontalScrollPolicy="off" verticalScrollPolicy="off" >
<mx:Text height="100%" width="100%" id="status" htmlText="" selectable="true" doubleClick="openDoc(event)" doubleClickEnabled="true"/>
<mx:Script>
<![CDATA[
var refId:String = "";
override public function set data(value:Object):void {
super.data = value;
//variables for setting text are created here
status.htmlText = 'Date: ' + data.refDate;
status.htmlText += '<br><font color="#666666">Status: ' + data.currStatus + '</font>';
}
// Opens a new browser window and loads the file
public function openDoc(event:MouseEvent):void {
//removed due to irrelevance
}
]]>
</mx:Script>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="lalala" dataField="serviceID" width="50"/><!---this is the dummy column that I created and is the only one that functions properly-->
</mx:columns>
</mx:DataGrid>
</mx:Application>
For some unknown reason, my popup AlertMsg is visually blocked by the StageWebView:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" applicationDPI="160" xmlns:local="*"
creationComplete="application1_creationCompleteHandler(event)"
backgroundColor="#112233">
<fx:Script>
<![CDATA[
import mx.core.FlexGlobals;
import mx.events.FlexEvent;
public var webView:StageWebView = new StageWebView();
public function StageWebViewExample():void
{
webView.stage = webContainer.stage;
// webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight );
webView.viewPort = new Rectangle( 100, 100, 500, 500 );
}
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
webContainer.addEventListener(Event.ADDED_TO_STAGE, function(ee:Event):void {
StageWebViewExample();
});
}
protected function btnTest_clickHandler(event:MouseEvent):void
{
webView.loadURL("http://www.example.com");
new AlertMsg().open(FlexGlobals.topLevelApplication as DisplayObjectContainer, true);
}
]]>
</fx:Script>
<fx:Declarations>
<fx:Component className="AlertMsg">
<s:SkinnablePopUpContainer x="70" y="300">
<s:TitleWindow title="My Message" close="close()">
<s:VGroup horizontalAlign="center" paddingTop="8" paddingBottom="8" paddingLeft="8" paddingRight="8" gap="5" width="100%">
<s:Label text="My alert message text here..."/>
<s:Button label="OK" click="close()"/>
</s:VGroup>
</s:TitleWindow>
</s:SkinnablePopUpContainer>
</fx:Component>
</fx:Declarations>
<s:Panel id="thePanel" title="Panel" backgroundColor="blue">
<s:Button id="btnTest" label="Test"
click="btnTest_clickHandler(event)" />
<s:BorderContainer id="webContainer" y="50" width="400" height="300" />
</s:Panel>
</s:Application>
Any idea?
I absolutly agree with #www.Flextras.com, there is no another workaround than substitute WebView by its snapshot. There is a ready solution http://www.judahfrangipane.com/blog/2011/01/16/stagewebview-uicomponent/
In a DataGrid, how can I force data() of all itemRenderers on visible rows to be called when I've made an update to the dataProvider.
I'n the following the Grid isn't updated after pressing doSomething. If I have a large list the update is done when scrolling down and then back up again, or in the case of the TreeGrid i open/close a node.
<?xml version="1.0" ?>
<mx:VBox
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:flexlib="http://code.google.com/p/flexlib/"
initialize="_initialize()">
<mx:Script>
<![CDATA[
import mx.events.CollectionEvent;
import mx.controls.Alert;
import Icons;
[Bindable]
private var dataProvider0:XML;
private function _initialize():void
{
dataProvider0 = <node>
<node label="A" option="1">
<node label="C" option="1"/>
<node label="D" option="1"/>
</node>
<node label="B" option="1">
<node label="E" option="1"/>
<node label="F" option="1"/>
</node>
</node>;
}
private function doSomething():void
{
dataProvider0.node[0].#option = 0;
dataProvider0.node[0].node[0].#option = 0;
}
]]>
</mx:Script>
<flexlib:TreeGrid
id="treeGrid1"
width="500"
height="300"
showRoot="false"
verticalTrunks="none"
paddingLeft="0"
disclosureClosedIcon="{Icons.folderClosed}"
disclosureOpenIcon="{Icons.folderOpen}"
dataProvider="{dataProvider0}">
<flexlib:columns>
<flexlib:TreeGridColumn dataField="#label" headerText="Section"/>
<mx:DataGridColumn dataField="#option" headerText="Option" width="50">
<mx:itemRenderer>
<mx:Component>
<mx:Box xmlns:mx="http://www.adobe.com/2006/mxml" paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0" verticalAlign="middle" horizontalAlign="center" width="100%" height="100%">
<mx:Script>
<![CDATA[
[Bindable]
override public function set data(value:Object):void
{
super.data = value;
chkMain.selected = value.#option == "1";
}
]]>
</mx:Script>
<mx:CheckBox id="chkMain"/>
</mx:Box>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</flexlib:columns>
</flexlib:TreeGrid>
<mx:DataGrid
id="dataGrid1"
width="500"
height="300"
dataProvider="{dataProvider0.node}">
<mx:columns>
<mx:DataGridColumn dataField="#label" headerText="Section"/>
<mx:DataGridColumn dataField="#option" headerText="Option" width="50">
<mx:itemRenderer>
<mx:Component>
<mx:Box xmlns:mx="http://www.adobe.com/2006/mxml" paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0" verticalAlign="middle" horizontalAlign="center" width="100%" height="100%">
<mx:Script>
<![CDATA[
[Bindable]
override public function set data(value:Object):void
{
super.data = value;
chkMain.selected = value.#option == "1";
}
]]>
</mx:Script>
<mx:CheckBox id="chkMain"/>
</mx:Box>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
<mx:Button label="Do" click="doSomething()"/>
</mx:VBox>
Have you tried
private function doSomething():void
{
dataProvider0.node[0].#option = 0;
dataProvider0.node[0].node[0].#option = 0;
// force a redraw at earliest opportunity
treeGrid1.invalidateDisplayList();
}
Try this:
private function doSomething():void
{
dataProvider0.node[0].#option = 0;
dataProvider0.node[0].node[0].#option = 0;
treeGrid1.dataProvider.refresh();
dataGrid1.dataProvider.refresh();
}
I'm looking for a Flash/Flex component which will create a "popup" editing balloon, similar to, for example, iCal or Google calendar:
http://img.skitch.com/20090526-phb5mke61anjkfknaekdbjjefw.jpg
(source: iusethis.com)
Does such a thing exist?
The Tooltip Control is what you're looking for. You might want to extend the class to allow for more advanced functionality.
there are fallowing code for balloon popup.
Atul Yadav
http://techy.limewebs.com
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="294" height="104"
backgroundAlpha="1.0" backgroundColor="#FFFFFF" borderColor="#1B86D1"
borderStyle="solid" creationComplete="DrowLine()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.core.Application;
import mx.managers.PopUpManager;
private function OnClose():void{
PopUpManager.removePopUp(this);
}
private function DrowLine():void{
var pt:Point = new Point(0, -13);
var global:Point = Application.application.localToGlobal(pt);
var origin:Point =global;
var destination:Point = new Point(150,0);
var destination1:Point = new Point(50,0);
var lineThickness:Number = 1;
var lineColor:Number = 0x1B86D1;
var lineAlpha:Number = 1;
//Alert.show(global.toString());
var tip:Canvas = new Canvas();
tip.graphics.clear();
tip.graphics.beginFill(0xffffff,1);
tip.graphics.lineStyle(lineThickness,lineColor,lineAlpha);
tip.graphics.moveTo(origin.x,origin.y);
tip.graphics.lineTo(destination.x,destination.y);
tip.graphics.lineStyle(1,0xffffff,lineAlpha);
tip.graphics.lineTo(50,0);
tip.graphics.lineStyle(1,0x1B86D1,1);
tip.graphics.lineTo(origin.x,origin.y);
tip.graphics.endFill();
addChild(tip);
}
]]>
</mx:Script>
<mx:TextArea x="10" y="25" width="274" id="txt_message" borderColor="#2487CC"/>
<mx:Label x="10" y="75" text="Attach:" width="54" fontWeight="bold" color="#000000"/>
<mx:Button x="58" y="73" label="Browse" cornerRadius="0" borderColor="#288ACF" color="#4DB111"/>
<mx:Button x="219" y="73" label="Save" id="btn_save" name="btn_save" cornerRadius="0" color="#15AE11" borderColor="#308FD1"/>
<mx:Image x="272" y="2" width="18" height="18" source="assets/Close.PNG" click="OnClose()"/>
</mx:Canvas>
Here is the sample code for my accordion:
<mx:Accordion x="15" y="15" width="230" height="599" styleName="myAccordion">
<mx:Canvas id="pnlSpotlight" label="SPOTLIGHT" height="100%" width="100%" horizontalScrollPolicy="off">
<mx:VBox width="100%" height="80%" paddingTop="2" paddingBottom="1" verticalGap="1">
<mx:Repeater id="rptrSpotlight" dataProvider="{aSpotlight}">
<sm:SmallCourseListItem
viewClick="PlayFile(event.currentTarget.getRepeaterItem().fileID);"
Description="{rptrSpotlight.currentItem.fileDescription}"
FileID = "{rptrSpotlight.currentItem.fileID}"
detailsClick="{detailsView.SetFile(event.currentTarget.getRepeaterItem().fileID,this)}"
Title="{rptrSpotlight.currentItem.fileTitle}"
FileIcon="{iconLibrary.getIcon(rptrSpotlight.currentItem.fileExtension)}" />
</mx:Repeater>
</mx:VBox>
</mx:Canvas>
</mx:Accordion>
I would like to include a button in each header like so:
Thanks, I got it working using FlexLib's CanvasButtonAccordionHeader.
You will have to create a custom header renderer, add a button to it and position it manually. Try something like this:
<mx:Accordion>
<mx:headerRenderer>
<mx:Component>
<AccordionHeader xmlns="mx.containers.accordionClasses.*">
<mx:Script>
<![CDATA[
import mx.controls.Button;
private var extraButton : Button;
override protected function createChildren( ) : void {
super.createChildren();
if ( extraButton == null ) {
extraButton = new Button();
addChild(extraButton);
}
}
override protected function updateDisplayList( unscaledWidth : Number, unscaledHeight : Number ) : void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
extraButton.setActualSize(unscaledHeight - 6, unscaledHeight - 6);
extraButton.move(unscaledWidth - extraButton.width - 3, (unscaledHeight - extraButton.height)/2);
}
]]>
</mx:Script>
</AccordionHeader>
</mx:Component>
</mx:headerRenderer>
<mx:HBox label="1"><Label text="Text 1"/></HBox>
<mx:HBox label="1"><Label text="Text 2"/></HBox>
<mx:HBox label="1"><Label text="Text 3"/></HBox>
</mx:Accordion>