Adding components to CoverFlow in Flex - apache-flex

I'm working with the CoverFlow library by Doug McCune.
In the example included, he has created some panels inside a CoverFlowContainer. There are other examples of him populating the coverflow from an RSS feed on the page linked above but he doesn't include the source for these :(
I will eventually be retrieving data from a web service to add to the coverflow however I'm starting with this simple example:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" horizontalAlign="center" verticalAlign="middle" xmlns:containers="com.dougmccune.containers.*" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.TextArea;
public var articlePanel:Panel = new Panel();
public var articleTextArea:TextArea = new TextArea();
private function init() : void
{
articlePanel.addChild(articleTextArea);
articlePanel.title = "test tile"
articleTextArea.text = "article1" + "\n" + "www.article.com" + "\n" + "hello this is article 1";
coverflow2.addChild(articlePanel);
}
]]>
</mx:Script>
<mx:VBox id="box" verticalGap="0" height="306" width="100%" maxWidth="600" maxHeight="300" >
<containers:CoverFlowContainer id="coverflow2" width="100%" height="244"
horizontalGap="40" borderStyle="inset" backgroundColor="0x000000"
segments="6" reflectionEnabled="true">
<mx:Panel id="testpanel" width="200" height="200" title="Mxml title">
<mx:DataGrid width="100%" height="100%">
<mx:columns>
<mx:DataGridColumn headerText="Column 1" dataField="col1"/>
<mx:DataGridColumn headerText="Column 2" dataField="col2"/>
<mx:DataGridColumn headerText="Column 3" dataField="col3"/>
</mx:columns>
</mx:DataGrid>
</mx:Panel>
<mx:Panel id="buttonpanel" width="200" height="200" title="Mxml title">
<mx:Button id="myButton" label="Change title" click="buttonpanel.title = ('hello') "/>
</mx:Panel>
</containers:CoverFlowContainer>
</mx:VBox>
</mx:Application>
I've defined some panels in the mxml and set creationComplete=init() so that the new panel I've created in ActionScript will be added to the CoverFlow container.
When I launch the application it displays the two predefined panels but not the one I have created in ActionScript.
Any ideas? Is there a better way of doing this?

you can try mx:Repeater component
<mx:HTTPService id="srv" url="pics.xml"/>
<ns2:CarouselContainer id="cf" width="100%" height="303" horizontalGap="40"
segments="6" reflectionEnabled="true" angle="10" >
<mx:Repeater id="r" dataProvider="{srv.lastResult.images.image}">
<mx:Canvas width="200" height="200">
<mx:Image source="{r.currentItem.src}"/>
</mx:Canvas>
</mx:Repeater>
</ns2:CarouselContainer>

Fixed this by first defining the coverflow container with nothing in it:
<containers:CoverFlowContainer id="coverflow" width="100%" height="244"
horizontalGap="40" borderStyle="inset" backgroundColor="0x000000"
reflectionEnabled="true"/>
In the actionscript section I retrieve an array from a web service and for each item in the array I create a panel. It is important to give each panel a width and height otherwise it will only show one element in the coverflow or no elements at all:
articlePanel.width = 200;
articlePanel.height = 200;

Related

how to replace the images in flex 3?

In my flex application, i am maintaining 5 images. When user clicks on 'next' button, it should display one image say 'image1'. If that button clicked again, then image1 should replace with image2 and so on. I am basically following 'image.visible' method. But images are displaying side by side. I think it is not the correct procedure. Any alternative? Thanks in advance
here is my code. I kept all my images and buttons in mx:panel. Even i used x and y positions which are not working.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Panel
title = 'Learn and Test your Knowledge'
height = '80%'
paddingBottom = '10' paddingTop = '10'
paddingLeft = '10' paddingRight = '10'
borderAlpha='0.20' fontFamily="Verdana" fontSize="15" color="#F30C32" backgroundImage="#Embed(source='../images/lad.jpg')" width="413" x="139">
<mx:Script>
<![CDATA[
public function nextEvent():void
{
// here i should write next button code
}
]]>
</mx:Script>
<mx:Image source="../images/image1.jpg" visible="true" id="image1" />
<mx:Image source="../images/image3.jpg" visible="true" id="image2"/>
<mx:Image source="../images/image3.jpg" visible="true" id="image3"/>
<mx:Button id="next" visible="false" click="nextEvent()">
</mx:Button>
The best way is to use only one image component if you are only ever showing one image. You can create an array or vector with the embedded images and reference that to change the source property on the image component. Here is an example: (the code below will work with any layout/container)
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Image id="image" click="imageClick()" source="{new images[0]()}" />
<mx:Script>
<![CDATA[
[Embed(source="assets/1.png")]
private var image1:Class;
[Embed(source="assets/2.png")]
private var image2:Class;
[Embed(source="assets/3.png")]
private var image3:Class;
private var images:Array = [image1, image2, image3];
private var imageIndex:uint = 0;
protected function imageClick():void
{
imageIndex++;
if(imageIndex == images.length) imageIndex = 0;
image.source = new images[imageIndex]();
}
]]>
</mx:Script>
</mx:Canvas>
Specify the x and y position of images as same and play around with their visibility.It ll definitely work.
ViewStack is my option it fits very well in this occasion.
At a time it shows only one component, for next action it will automatically override previous content by its new component.
<mx:ViewStack id="myViewStack" borderStyle="solid" width="100%" height="80%">
<mx:Canvas id="one" click="myViewStack.selectedChild=two;">
<mx:Image source="assets/1.png" />
</mx:Canvas>
<mx:Canvas id="two" click="myViewStack.selectedChild=three;">
<mx:Image source="assets/2.png" />
</mx:Canvas>
<mx:Canvas id="three" click="myViewStack.selectedChild=four;">
<mx:Image source="assets/3.png" />
</mx:Canvas>
<mx:Canvas id="four" click="myViewStack.selectedChild=five;">
<mx:Image source="assets/4.png" />
</mx:Canvas>
<mx:Canvas id="five" click="myViewStack.selectedChild=one;">
<mx:Image source="assets/5.png" />
</mx:Canvas>
</mx:ViewStack>

Flex: Double click event propagation on datagrid dependent on component order?

I'd like to have a double click event on a datagrid in Flex3. The following example only works if the Accordion (id = "mustBeSecond") container comes after the DataGrid. Why is the order of the components important and what can I do to prevent this behavior?
(The example does not work. If you change the order of "mustBeSecond" and "gridReportConversions" the example works fine)
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.collections.ArrayCollection;
[Bindable] private var dp:ArrayCollection = new ArrayCollection([
{qty:1,referer:'http://google.com'},
{qty:25,referer:'http://cnn.com'},
{qty:4,referer:'http:stackoverflow.com'}]);
private function refererRowDoubleClicked(e:Event):void {
Alert.show("double click");
}
]]>
</mx:Script>
<mx:HBox width="100%" height="100%">
<mx:Accordion width="200" height="200" id="mustBeSecond">
<mx:Canvas label="Navigation Box" width="100%" height="100%">
<mx:VBox>
<mx:LinkButton label="First Link" />
<mx:LinkButton label="Second Link" />
</mx:VBox>
</mx:Canvas>
</mx:Accordion>
<mx:DataGrid id="gridReportConversions" height="100%" width="100%" dataProvider="{this.dp}"
mouseEnabled="true" doubleClickEnabled="true" itemDoubleClick="refererRowDoubleClicked(event)">
<mx:columns>
<mx:DataGridColumn width="75" dataField="qty" headerText="Qty" />
<mx:DataGridColumn dataField="referer" headerText="URL" />
</mx:columns>
</mx:DataGrid>
</mx:HBox>
I tested your code in Flex and it didn't make any difference which order they were in. The double click event fired either way. This was in a fresh project with no other code except the default stuff that a Flex application sets you up with.
Sometimes when a Flex project starts acting weird it helps to go to click Project -> Clean.
Do you get any errors or notices showing up in the Problems pane?

how to pass an array of values from one mxml component to another in Flex?

I have a mxml component with a datagrid listing project names and code versions. I have the selected projects from the datagrid binded to a public variable named "selectedProjects". But how to access this variable in another mxml component. I want the selected project's name in that component's text area. how to do that?
I even created an instance of the first component and using that called the selectedProjects variable. But I do not get the value updated in the text area.
This is the code for the first component where I get the selected projects name in a variable:
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="handleCreationComplete();"
width="800" height="600">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.managers.PopUpManager;
import mx.collections.ArrayCollection;
import mx.events.ItemClickEvent;
[Bindable] public var selectedProjects:Array;
private function handleCreationComplete():void {
PopUpManager.centerPopUp(this);
}
public var pages:ArrayCollection=new ArrayCollection([
{label:"10"},
{label:"20"},]);
public var projectList:ArrayCollection=new ArrayCollection([
{ItemName:"User Requirement Specification",ItemCodeVersion:"URS - 1"},
{ItemName:"User Requirement Specification",ItemCodeVersion:"URS - 2"},
{ItemName:"Software Requirement Specification",ItemCodeVersion:"SRS - 2.1"},
{ItemName:"Software Design Specification",ItemCodeVersion:"SDS - 2"},
{ItemName:"Software Design Specification",ItemCodeVersion:"SRS - 1.1"},
{ItemName:"User Manual",ItemCodeVersion:"User Manual - 1"},
{ItemName:"User Manual",ItemCodeVersion:"User Manual - 2.1"},]);
private function close():void
{
PopUpManager.removePopUp(this);
}
private function select():void
{
Alert.show(projectListDG.selectedItem.ItemName);
PopUpManager.removePopUp(this);
}
]]>
</mx:Script>
<mx:Binding source="projectListDG.selectedItems" destination="selectedProjects" />
<mx:Label styleName="labelHeading" text="Project Documents List"/>
<mx:Panel width="100%" height="100%" layout="vertical" title="Documents List" >
<mx:HBox>
<mx:Label text="Show"/>
<mx:ComboBox dataProvider="{pages}" width="60" />
<mx:Label text="results per page" />
</mx:HBox>
<mx:DataGrid id="projectListDG" dataProvider="{projectList}" allowMultipleSelection="true" rowCount="10" width="100%" height="100%">
<mx:columns>
<mx:DataGridColumn headerText="Select" itemRenderer="mx.controls.CheckBox" textAlign="center" width="50"/>
<mx:DataGridColumn headerText="Item Name" dataField="ItemName" textAlign="center" />
<mx:DataGridColumn headerText="Item Code - Version" dataField="ItemCodeVersion" textAlign="center" width="150 " />
</mx:columns>
</mx:DataGrid>
<mx:Label text="{projectListDG.selectedItem.ItemName}"/>
</mx:Panel>
<mx:HBox horizontalAlign="center" width="100%">
<mx:Button label="Select" click="select();"/>
<mx:Button label="Cancel" click="close();"/>
</mx:HBox>
</mx:TitleWindow>
I now have the selected projects in the selectedProjects variable.
Now this is the second componenent in which I am trying to make use of the project name.
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.core.IFlexDisplayObject;
import mx.managers.PopUpManager;
import mx.containers.TitleWindow;
[Bindable]
public var projectList:projDocsLookUp=new projDocsLookUp();
//Datagrid
[Bindable]
private var defectDetails:ArrayCollection = new ArrayCollection([
{Select:true},
]);
private function projDocsPopUp():void{
var helpWindow:TitleWindow = TitleWindow(PopUpManager.createPopUp(this, projDocsLookUp, true));
helpWindow.title="Project Documents List";
}
]]>
</mx:Script>
<mx:Label styleName="labelHeading" text="Defect Entry - Verification" />
<mx:Panel width="100%" height="30%" layout="vertical" title="Review Report Details">
<mx:VBox width="100%">
<mx:FormItem label="Project Name:" width="100%">
<mx:Text text="IPMS"/>
</mx:FormItem>
<mx:HRule width="100%"/>
<mx:VBox>
<mx:FormItem label="Project Documents:">
<mx:HBox>
<!--text="{projectList.projectListDG.selectedItem.ItemName}"-->
<mx:TextArea id="projDocs" width="150" text="{projectList.selectedProjects}" />//text area field is not updated.
<mx:Button width="30" label=".." click="projDocsPopUp();"/>
</mx:HBox>
</mx:FormItem>
</mx:VBox>
</mx:Panel>
<mx:Panel width="100%" height="50%" layout="vertical" title="Defect Details" >
<mx:DataGrid id="defectDG" dataProvider="{defectDetails}" variableRowHeight="true" width="100%" height="75" >
<mx:columns>
<mx:DataGridColumn dataField="Select" itemRenderer="mx.controls.CheckBox" width="50" textAlign="center" />
<mx:DataGridColumn dataField="Defect Id" itemRenderer="mx.controls.TextInput" textAlign="center"/>
<mx:DataGridColumn dataField="Status" itemRenderer="mx.controls.ComboBox" textAlign="center"/>
</mx:columns>
</mx:DataGrid>
</mx:Panel>
</mx:VBox>
I was trying to update the value of the selected projects in the text area of Id "projDocs", But I do not get it.. Please some one help me..
Well I found out the solution by myself..
Googling of course. I followed the method given in this tutorial.
I added a reference to the parent application's TextArea control. The pop up component uses that reference to update the first component's TextArea.
In the first component, I changed the function that creates the pop up as
private function projDocsPopUp():void{
var helpWindow:projDocsLookUp = projDocsLookUp(PopUpManager.createPopUp(this, projDocsLookUp, true));
helpWindow.title="Project Documents List";
helpWindow.showCloseButton=true;
helpWindow.targetComponent=projDocs; //I get the value returned by the pop up window here
And then in the pop up component, changed the select function as:
private function select():void
{
var i:int;
for(i=0;i<selectedProjects.length;i++)
{
targetComponent.text+=selectedProjects[i].ItemName+",";
}
PopUpManager.removePopUp(this);
}
And finally I get the project name updated in the first components text area box.

sending entire columns of Datagrid from flex to PHP

My Main.MXML
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:mate="http://mate.asfusion.com/" width="100%" height="100%">
<mx:AdvancedDataGrid sortExpertMode="true" id="baselineGrid" dataProvider="{dataSource}"
headerSeparatorSkin="mx.skins.ProgrammaticSkin"
headerSortSeparatorSkin="mx.skins.ProgrammaticSkin" paddingLeft="30" variableRowHeight="true" width="296" x="32" y="143">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="col2" width="100" headerText="Weightage" />
<mx:AdvancedDataGridColumn id="baseL" dataField="col3" itemRenderer="DetailGrid" headerText="Define Baseline" width="50" />
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Canvas>
ItemRenderer
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:NumberValidator id="Baseline_Val" source="{baselineRating}" required="true"
lowerThanMinError="This field is required."
property="selectedIndex"
minValue="0" />
<mx:ComboBox prompt="Select" id="baselineRating" change="getValue()" width="100">
<mx:String></mx:String>
<mx:String>0</mx:String>
<mx:String>1</mx:String>
<mx:String>2</mx:String>
<mx:String>3</mx:String>
</mx:ComboBox>
</mx:HBox>
I need to send the entire datagrid columns to PHP. How to send all the values of the column 1 and column 2.
Note: COlumn 2 is an itemRenderer which has a combo box.
Convert the collection into a suitable format like xml or json and send it through URLLoader.
var result:XML = <root/>;
for each(var item:Object in dataSource)
{
//declare itemToString based on your needs.
result.appendChild("<item>" + itemToString(item) + "</item>");
}

Cannot get itemDoubleClick event to work in Flex (even with doubleClickEnabled=true)

I am trying to do a simple datagrid in Flex with a doubleclick event, but I cannot get itemDoubleClick to fire:
<mx:DataGrid id="gridReportConversions" height="100%" width="100%" mouseEnabled="true" doubleClickEnabled="true" itemDoubleClick="refererRowDoubleClicked(event)">
<mx:columns>
<mx:DataGridColumn width="75" dataField="qty" headerText="Qty" />
<mx:DataGridColumn dataField="referer" headerText="URL" />
</mx:columns>
</mx:DataGrid>
If I use the itemClicked event then the event is raised just fine. When I search for this problem I find many people saying 'you need to set doubleClickEnabled=true, but I've done that and it still doesn't work.
This control is nested within quite a few levels of VBox and other containers. Surely I dont need to set doubleClickEnabled on each of those containers do I?
Just to clarify how I tested this - I have an alert box in my refererRowDoubleClicked event handler and it never gets shown when I use itemDoubleClick
Simon,
I was able to get your code to work, no problem. Wrapped it up in several layers of containers that didn't have doubleClickEnabled set to true, to see if that was an issue, but it doesn't seem to be.
I'm wondering if one of the parents is causing a problem somehow. Would it be possible for you to post a larger section of the code?
Here is what I ran to test this with:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.collections.ArrayCollection;
[Bindable] private var dp:ArrayCollection = new ArrayCollection([{qty:1,referer:'http://google.com'},{qty:25,referer:'http://cnn.com'},{qty:4,referer:'http:stackoverflow.com'}]);
private function refererRowDoubleClicked(e:Event):void
{
var msg:String = "target: " + e.target + "\n\ncurrentTarget: " + e.currentTarget + "\n\nselected item qty: " + gridReportConversions.selectedItem.qty + "\nselected item referer: " + gridReportConversions.selectedItem.referer;
Alert.show(msg);
}
]]>
</mx:Script>
<mx:VBox width="100%" height="100%">
<mx:VBox width="100%" height="100%">
<mx:Box width="100%" height="100%">
<mx:Canvas width="100%" height="100%">
<mx:DataGrid id="gridReportConversions" height="100%" width="100%" dataProvider="{this.dp}"
mouseEnabled="true" doubleClickEnabled="true" itemDoubleClick="refererRowDoubleClicked(event)">
<mx:columns>
<mx:DataGridColumn width="75" dataField="qty" headerText="Qty" />
<mx:DataGridColumn dataField="referer" headerText="URL" />
</mx:columns>
</mx:DataGrid>
</mx:Canvas>
</mx:Box>
</mx:VBox>
</mx:VBox>
</mx:Application>
Before I use the propety doubleClickEnabled, my itemDoubleClick doesn't work, but when I set doubleClickEnabled=true, it work good, no problem.

Resources