Flex3: Component Declarations are Not Allowed Here error - apache-flex

I'm getting the "Component declarations are not allowed here error" where I've got my RadioButtonGroup. Below is the custom component.
Why can't I put a RadioButtonGroup in it?
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.controls.RadioButton;
import mx.controls.RadioButtonGroup;
public function removeMe(event:MouseEvent):void {
this.removeChild(event.currentTarget as DisplayObject);
}
]]>
</mx:Script>
<mx:Panel width="500" height="400" title="hello" click="removeMe(event)">
<mx:Text text="My Text" />
<mx:RadioButtonGroup>
<mx:RadioButton label="A"/>
<mx:RadioButton label="B"/>
<mx:RadioButton label="C"/>
</mx:RadioButtonGroup>
</mx:Panel>
</mx:Canvas>
Any advice on how to solve this problem. I'm using Flex 3, SDK 3.2.
Thank you.
-Laxmidi

A RadioButtonGroup is not a container and therefore cannot have Children in the manner you're setting it up. Add a RadioButton to a group using the groupName property on the RadioButton instance. Like this:
<mx:RadioButtonGroup id="rbg" />
<mx:RadioButton label="A" groupName="rbg"/>
<mx:RadioButton label="B" groupName="rbg"/>
<mx:RadioButton label="C" groupName="rbg"/>

Related

Flex 4: tabIndex is not working inside form

tabIndex is not working properly in the below flex code.
mx:AddChild tag is used to add Login.mxml in index.mxml as shown below:
index.mxml
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:login="com.states.login.*"
initialize="init()"
pageTitle="Demo" >
<mx:Script>
<![CDATA[
public function init():void {
Application.application.currentState = 'initState';
}
]]>
</mx:Script>
<mx:states>
<mx:State name="initState">
<mx:AddChild relativeTo="{MainCanvas}" position="lastChild">
<login:Login id="Login"/>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:VBox>
<mx:Canvas width="100%" height="100%" id="MainCanvas">
</mx:Canvas>
</mx:VBox>
</mx:Application>
Login.mxml
<mx:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx" >
...
<mx:Form>
<mx:FormItem label="Username:">
<mx:TextInput id="username" tabEnabled="true" tabIndex="1"/>
</mx:FormItem>
<mx:FormItem label="Password:">
<mx:TextInput id="password" displayAsPassword="true" tabEnabled="true" tabIndex="2"/>
</mx:FormItem>
</mx:Form>
...
Tabbing is working when focus is outside the form in browser. But does not work when focus is inside the TextInput control.
The issue was resolved after doing below 2 changes:
Move the code in Login.mxml into index.mxml and removed AddChild method.
year is set to 2006 in xmlns:mx and xmlns:fx namespaces. (Not sure if this was the issue)
How to resolve the tabbing issue without removing AddChild method.

How to display images from FileReferenceList?

I have a FileReferenceList from which I'd like to display images in a DataGrid; currently I'm getting the following error: Only one download, upload, load or save operation can be active at a time on each FileReference. Following is my code; anyone know how to resolve the error I'm getting? Thanks.
Here is my DataGrid:
<s:Panel>
<mx:DataGrid id="imageGrid" width="100%" height="100%" dataProvider="{imageFiles}">
<mx:columns>
<mx:DataGridColumn itemRenderer="renderers.GridImgRenderer" headerText="Image"/>
<mx:DataGridColumn dataField="name" headerText="Image Name"/>
<mx:DataGridColumn dataField="size" headerText="Image Size"/>
</mx:columns>
</mx:DataGrid>
<s:controlBarContent>
<s:Button id="browse" label="Browse" click="browseHandler(event)"/>
<s:Button id="upload" label="Upload"/>
</s:controlBarContent>
<s:controlBarLayout>
<s:HorizontalLayout horizontalAlign="center" paddingBottom="5" paddingTop="5"/>
</s:controlBarLayout>
</s:Panel>
Here's my renderer:
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true" creationComplete="init()">
<fx:Script>
<![CDATA[
private function init():void
{
data.addEventListener(Event.COMPLETE, function(event:Event):void
{
imagePreview.source = event.target.data;
});
data.load();
}
]]>
</fx:Script>
<mx:Image id="imagePreview" width="200" maintainAspectRatio="true" scaleContent="true"/>
</s:MXDataGridItemRenderer>
Try this It May help You.
http://blog.snowflax.com/multiple-image-browse-using-filereferencelist-in-flex/
Well for starters, your renderer is wrong. You'll run into problems when they are recycled.
To answer your main question, you are probably running into the security issue around file access and user initiated events.
Its a thorny issue and I suggest reading the documentation on it!

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.

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