Problem creating a TileList with Canvases which are drag-able - apache-flex

I want to create a tilelist in which there would be different canvas or vbox etc, and i want to make them drag able.
I wrote a code to do this, but the output does not shows anything in a list.
<mx:TileList width="1500" height="1000" dragMoveEnabled="true"
selectable="true" selectionColor="#FFFFFF"
dragEnabled="true" dropEnabled="true"
columnCount="1" rowHeight="160">
<mx:dataProvider>
<mx:Array>
<mx:Canvas width="1450" height="100">
<mx:Button label="Testin the buttong"/>
</mx:Canvas>
<mx:Canvas width="1450" height="100">
<mx:Button label="Testin"/>
</mx:Canvas>
</mx:Array>
</mx:dataProvider>
</mx:TileList>
How can I fix this? Or let me know what m i doing wrong here?
Thanks and Regards
Zeeshan

Your dataProvider should have objects of some sort. In theory they could be instance of a Canvas, but that would be highly unusual to use a visual component as the dataProvider. What you want to do is read up on itemRenderers. an itemRenderer is a component that will be used to renderer each instance of your dataProvider.
Try something like this:
<mx:script><[[
public var mydb : Array = [
{label: 'Testin the buttong'},
{label: 'Testin'}
]
]]></mx:script>
<mx:TileList width="1500" height="1000" dragMoveEnabled="true"
selectable="true" selectionColor="#FFFFFF"
dragEnabled="true" dropEnabled="true"
columnCount="1" rowHeight="160" dataProvider="{mydp}">
<mx:itemRenderer>
<mx:Component>
<mx:Canvas width="1450" height="100">
<mx:Button label="{data.label}"/>
</mx:Canvas>
</mx:Component>
</mx:itemRenderer>
</mx:TileList>
In short I Defined the dataProvider in script with generic objects. And I defined an itemRenderer in-line. Something like this should at least have something show up.
I'm not sure if a Canvas can be draggable, as it doesn't usually have anything to click on to start the drag. You may want to consider a TitleWindow.
I wrote the code in browser, so standard disclaimers apply.

Related

Flex - how to create a simple inline checkbox itemeditor in a spark datagridcolumn?

Looking at the flex 4.6 (flash builder) documentation, it shows an example of creating an item editor for a data grid column, but their example is using the "mx" library. I am trying to stick to using the spark library. I can not seem to come up with equivelent working code in spark:
Here is their code:
<mx:itemEditor>
<fx:Component>
<mx:VBox backgroundColor="yellow">
<fx:Script>
<![CDATA[
// Define a property for returning
// the new value to the cell.
[Bindable]
public var cbSelected:Boolean;
]]>
</fx:Script>
<mx:CheckBox id="followUpCB"
label="Follow up needed"
height="100%" width="100%"
selected="{data.FollowUp}"
click="cbSelected=followUpCB.selected"/>
</mx:VBox>
</fx:Component>
</mx:itemEditor>
</mx:DataGridColumn>
I want to do exactly the same thing, but using a spark data grid and , spark check box and VGroup, etc.
Is it possible/how?
Update: A little progress, I have it partially working now by looking at various examples. It draws the check box, and I am able to click the check box to change the value, HOWEVER, it seems like it is not triggering the data grid to change/update. For example, I have to edit a different field in the data grid in order for the data grid to update and save back to the sever. I am using gridItemEditorSessionSave event:
<s:DataGrid id="recsDG" width="100%" height="100%" dataProvider="{_recs}"
editable="true" gridItemEditorSessionSave="recsDG_gridItemEditorSessionSaveHandler(event)" alternatingRowColors="[#FFFFFF, #CCCCCC]">
...
<s:GridColumn headerText="active" dataField="active" rendererIsEditable="true" >
<s:itemRenderer>
<fx:Component>
<s:GridItemRenderer>
<s:CheckBox id="test124" selected="{(data.active==1)}"
change="{data.active=int(test124.selected)}"/>
</s:GridItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:GridColumn>

Flex datagrid component problem

Guys I've a grid view in flex,
one of the columns is rendered like this:
<mx:DataGridColumn headerText="Cancel" >
<mx:itemRenderer>
<fx:Component>
<mx:Box width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
<mx:Button label="Download" width="100%" >
<mx:click>someFunction();</mx:click>
</mx:Button>
</mx:Box>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
now I've a problem that the function in button click is not being recognized. It says "call to a possibly undefined function" even though it was defined. What is wrong with this? How do i make a button in a grid call a function in the same mxml file??
thanks
Your itemRenderer is considered its own encapsulated component so it's looking for someFunction() within the itemRenderer itself. To call a function you have defined in the mxml file that contains your DataGrid, try calling the function using outerDocument.someFunction();.
If you would like to define the function at the itemRenderer level, you could do something like this:
<mx:itemRenderer>
<fx:Component>
<mx:VBox>
<fx:Script>
<![CDATA[
public function someFunction():void
{
// Do Something
}
]]>
</fx:Script>
<mx:Button click="someFunction();"/>
</mx:VBox>
</fx:Component>
</mx:itemRenderer>

How to use Image as the Selection and Hovering background in Flex DataGrid?

I want to display an image instead of Color in item Selection and Hovering(mouse over) in Flex DataGrid. how i can do it ?
You could do this with an inline item renderer or a custom item renderer. Here's a quick and dirty example of how to do it with an inline item renderer. You'll probably want to tweak this a bit to fit your solution but it should give you a good starting point.
<mx:DataGrid dataProvider="{myDataProvider}">
<mx:columns>
<mx:DataGridColumn dataField="someDataField" width="100">
<mx:itemRenderer>
<fx:Component>
<mx:Canvas mouseOver="myImage.visible = true" mouseOut="myImage.visible = false" width="100">
<mx:Label text="{data.someDataField}" width="100%" x="0" y="0" />
<mx:Image id="myImage" x="0" y="0" source="{outerDocument.myImageClass}" visible="false" />
</mx:Canvas>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
let say you have a
<mx:image id="img" src="sample.jpg" mouseOver="onHover()" mouseOut="onOut()"/>
a function
private function onHover():void{
img.src="sample2.jpg";
img.validateNow();
}
private function onOut():void{
img.src = "sample.jpg";
img.validateNow();
}
See if this works. not yet tested but the logic maybe there.

Flex - Data binding not working

I'm having some troubles with binding data.
I have an application that contains a viewstack of components.
Let's say I have comp1, comp2 and comp3 inside the viewstack.
Each component, has its own data class --> comp1Data.as, comp2Data.as and comp3Data.as.
All values in each component are binded to the corresponding data in it's data object.
A click in a control in comp1 leads to comp3, the same goes for comp2. Clicking a control in comp2 leads to comp3.
When going from comp1 to comp3, comp3Data.as is initialized and and comp3 displays the binded values.
When going from comp2 to comp3, comp3Data.as is also initialized but the binded values are not displayed...
I tried using an initialize but it is not working. And when debugging, the data is right there, but it's is not displaying.
Any help would be really appreciated.
Regards,
BS_C3
Some code ^__^
Main application:
<mx:Application>
<mx:Script>
<![CDATA[
private function order(s:String):void
{
if(s == 'order')
OrderData.instance.state = 'order';
else if(s == 'reporting')
{
OrderData.instance.state = 'reporting';
.
.
.
}
pages.selectedChild = or;
}
]]>
</mx:Script>
<mx:ViewStack id="pages" horizontalCenter="0" verticalCenter="0" width="100%" height="100%">
<components:SearchResult id="sr" width="100%"
order="order('order')"
/>
<components:Reporting id="rp" width="100%"
reportingOrder="order('reporting')"/>
<components:Order id="or" width="100%"
/>
</mx:ViewStack>
</mx:Application>
Both SearchResult and Reporting acces Order.
Order.mxml looks like this:
<mx:Canvas>
<mx:HBox width="100%">
<mx:Box paddingBottom="15" paddingLeft="15" paddingRight="15" paddingTop="15" backgroundColor="#FFFFFF" height="100%">
<components:OrderView id="ov"/>
</mx:Box>
<mx:Spacer width="15"/>
<components:OrderedSDR id="sdr" height="100%"/>
</mx:HBox>
</mx:Canvas>
I'm getting troubles with OrderedSDR.mxml:
<mx:Canvas>
<mx:VBox width="100%" height="100%" paddingBottom="28" paddingLeft="28" paddingRight="28" paddingTop="28" backgroundColor="#FFFFFF">
<mx:HBox width="100%" paddingBottom="6" horizontalAlign="center">
<mx:Canvas>
<mx:Image id="thumbnailBG" source="#Embed(source='assets/Images/SearchResult/BoxBagueOverview.PNG')"/>
<mx:Image id="overview" source="{GlobalData.instance.collection.overview.toString()}"/>
<mx:Label id="thumbnailCarats"
text="{GlobalData.instance.collection.carats.toString() + GlobalData.instance.languageProperties.orderedSDR.imageInfo.toString()}"
styleName="OVLBL"
paddingBottom="5" paddingRight="10"
x="{thumbnailBG.x + thumbnailBG.width - thumbnailCarats.width}"
y="{thumbnailBG.y + thumbnailBG.height - thumbnailCarats.height}"/>
</mx:Canvas>
</mx:HBox>
<mx:VBox id="mainBox" paddingBottom="8" paddingTop="8" verticalGap="6" width="180">
<mx:HBox width="100%" height="13">
<mx:Label width="80"
text="{GlobalData.instance.languageProperties.orderedSDR.product.toString()}"
styleName="OVDataLbl" opaqueBackground="#ECE5E2"/>
<mx:Label text="{SearchResultData.instance.selectedSDR.matnr_fp}" styleName="OVData"/>
</mx:HBox>
<mx:HBox width="100%" height="13">
<mx:Label width="80"
text="{GlobalData.instance.languageProperties.orderedSDR.netPrice.toString()}"
styleName="OVDataLbl" opaqueBackground="#ECE5E2"/>
<mx:Label text="{SearchResultData.instance.selectedSDR.currSymbol + ' ' + SearchResultData.instance.selectedSDR.fNet_price_fp}" styleName="OVData"/>
</mx:HBox>
.
.
.
</mx:VBox>
</mx:VBox>
</mx:Canvas>
Inside mainBox, I've got a list of hbox with the same structure as shown in the first two Hboxes.
Regarding the datasources, these are the following datasources that I'm using, their expected behaviour and their actual behaviour:
#
Embed(source='assets/Images/SearchResult/BoxBagueOverview.PNG --> The image is displayed as it should
GlobalData.instance.collection.overview.toString() --> GlobalData.instance.collection is a XMLList that contains the data for the image with id="overview". I do get the correct source, but the image is not displayed.
GlobalData.instance.languageProperties. ... --> It's a XMLList. The data is shown as it should.
SearchResultData.instance.selectedSDR.matnr_fp --> SearchResultData.instance.selectedSDR is an object that contains all the data that has to be displayed. Matnr_fp is a property of this object. And each hbox inside mainbox have to display a property of the object selectedSDR. The only property that is being displayed is SearchResultData.instance.selectedSDR.currSymbol. The other properties are not displaying even if the datasource is populated.
Hope this will be useful.
Thanks!
Regards,
BS_C3
Looks like nobody's seen anything wrong with the code??
Me neither. But doing other modifications on the code, it finally worked. Still don't know why... >_<

Error 1120: Access of undefined property

I have a <mx:Script> on the main file, where I define this:
[Bindable]
private var dpCols:ArrayCollection = new ArrayCollection([
{'prx':'bl', 'nmb':'Blanco', 'ral':'RAL1013', 'hex':'E8E4CD'},
{'prx':'am', 'nmb':'Amarillo', 'ral':'RAL1005', 'hex':'C79E03'},
{'prx':'gr', 'nmb':'Gris Perla', 'ral':'RAL7045', 'hex':'8E939E'}
]);
I can use it as a dataProvider in many places, but not here:
<mx:TileList dataProvider="{dpCols}">
<mx:itemRenderer>
<mx:Component>
<mx:Box backgroundColor="{int('0x' + data.hex)}"
height="64" width="72">
<mx:Label text="{data.ral}" textAlign="center" width="100%"/>
<mx:Label text="{data.nmb}" textAlign="center" width="100%"/>
</mx:Box>
</mx:Component>
</mx:itemRenderer>
</mx:TileList>
This TileList is within a <radg:RaDG> (my subclass for AdvancedDataGrid), <radg:columns>, <mx:AdvancedDataGridColumn>, <mx:itemEditor> and <mx:Component>. If I put it outside, it just works. But I need it to put it has the itemEditor.
How should I refer to dpCols then? (or how can I solve this error?)
Thanks!
You need outerDocument, since you're inside the <mx:Component> tag. See the "Using the Component Tag" section in this Adobe docs page or this SO question.
If you're getting particularly tricky with nesting, you may need to use parentDocument instead, but it sounds like outerDocument should work in your case (only one nesting of <mx:Component> tags).
Usage:
<mx:TileList dataProvider="{outerDocument.dpCols}" />

Resources