I wrote a component that displays a filename, a thumbnail and has a button to load/play the file. The component is databound to a repeater. How can I make it so that the button event fires to the main application and tells it which file to play?
On your custom component you can listen to the button click event and then generate a custom event that holds information about the file you want to play. You can then set the bubbles property to true on the event and dispatch the custom event from your custom component. The bubbles property will make your event float up the display list and reach your main application. Now on your main application you can listen to that event and play the correct file. Hope this helps.
Figured it out (finally)
Custom Component
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" x="0" y="0" width="215" height="102" styleName="leftListItemPanel" backgroundColor="#ECECEC" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Script>
<![CDATA[
[Bindable] public var Title:String = "";
[Bindable] public var Description:String = "";
[Bindable] public var Icon:String = "";
[Bindable] public var FileID:String = "";
private function viewClickHandler():void{
dispatchEvent(new Event("viewClick", true));// bubble to parent
}
]]>
</mx:Script>
<mx:Metadata>
[Event(name="viewClick", type="flash.events.Event")]
</mx:Metadata>
<mx:Label x="11" y="9" text="{String(Title)}" styleName="listItemLabel"/>
<mx:TextArea x="11" y="25" height="36" width="170" backgroundAlpha="0.0" alpha="0.0" styleName="listItemDesc" wordWrap="true" editable="false" text="{String(Description)}"/>
<mx:Button x="20" y="65" label="View" click="viewClickHandler();" styleName="listItemButton" height="22" width="60"/>
<mx:LinkButton x="106" y="68" label="Details..." styleName="listItemLink" height="18"/>
<mx:HRule x="0" y="101" width="215"/>
The Repeater
<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().fileName);"
Description="{rptrSpotlight.currentItem.fileDescription}"
FileID = "{rptrRecentlyViewed.currentItem.fileName}"
Title="{rptrSpotlight.currentItem.fileTitle}" />
</mx:Repeater>
</mx:VBox>
</mx:Canvas>
Handling function
private function PlayFile(fileName:String):void{
Alert.show(fileName.toString());
}
Related
I have a create characters component with a tabnavigator and textarea. In my main app I want to save the textarea id - mainchar text to the tag. I tried dotnotation, nothing, I tried import components.CreateCharacter; and still nothing, and tried some other options found on the net but can't get this to work.
Note, the code works fine if I call components in the main app, so the code works fine it is just the calling of the component (CreateCharacters) in the components folder. The components folder is in the src folder. Here is the code:
Main.mxml
<fx:Script>
<![CDATA[
import components.CreateCharacters
[Bindable]
public var xmlData:XML=<ROOTS></ROOTS>;
public function sav_clickHandler(event:MouseEvent):void
{
var fr:FileReference = new FileReference();
var ba:ByteArray = new ByteArray();
var newXmlRow:XML=<ROOTS>
<TXT>{components.CreateCharacters.mainchar.text}</TXT>// The problem lies with this line
<TXTA>{txt2.text}</TXTA>
<DTF>{txt3.text}</DTF>
</ROOTS>;
ba.writeMultiByte(newXmlRow, 'utf-8');
fr.save(ba);
}
private var openedFile:File;
private function open_clickHandler(event:MouseEvent):void {
openedFile = new File();
openedFile.addEventListener(Event.SELECT, file_select);
openedFile.browseForOpen("Please select a file...");
}
private function file_select(event:Event):void {
if(openedFile != null && openedFile.exists){
var fileStream:FileStream = new FileStream();
fileStream.open(openedFile, FileMode.READ);
var readXML:XML = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
fileStream.close();
trace(readXML.toString());
CreateCaracters.maichar.text = readXML.TXT;
txt2.text = readXML.TXTA;
txt3.text = readXML.DTF;
}
trace(event);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<net:FileReference id="fileReference" />
</fx:Declarations>
<s:Image x="0" y="0" width="100%" height="50" scaleMode="stretch"
source="assets/imaginationFly.png"/>
<s:Image x="12" y="1" source="assets/ECWDove.png"/>
<mx:TabNavigator x="1" y="49" width="100%" height="100%" backgroundColor="#7EB7C5"
chromeColor="#85B5BF">
<s:NavigatorContent width="100%" height="100%" label="Start">
<s:TextArea id="txt2" x="57" y="29"/>
</s:NavigatorContent>
<s:NavigatorContent id="Characters" width="100%" height="100%" label="Characters">
<components:CreateCharacters id="creatchr" width="100%" height="100%"/>
</s:NavigatorContent>
<s:NavigatorContent width="100%" height="100%" label="Worlds">
<s:TextArea id="txt3" x="55" y="10"
text="hello
I am testing this shit
hope it works"/>
<s:Button id="sav" x="285" y="138" label="Save" click="sav_clickHandler(event)"/>
<s:Button id="open" x="381" y="138" label="Open" click="open"/>
etc...
CreateCharaters.mxml (component)
<?xml version="1.0" encoding="utf-8"?>
<s:HGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
chromeColor="#0106BD" paddingLeft="10" paddingRight="0">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:ViewStack id="Characters" x="172" y="10" width="81" height="100%" backgroundColor="#030BB3"
chromeColor="#D7D7D8" paddingLeft="5" paddingRight="15">
<s:NavigatorContent id="Hero" width="100%" height="95%" label="Main Charater">
<s:HGroup width="100%" height="100%">
<s:TextArea id="mainchar" bottom="0" width="80%" height="100%"
chromeColor="#7070FD">//this is the textarea I want to use
<s:text><![CDATA[
Name:
Surname:
Nickname:
Hair Color:
etc...
Any help please
Why would you need binding in that case?
Your XML node is created and the text property is evaluated inside the same function so it should not be a problem. In other words, when the event handler is called, the current value of text will be copied inside your XML node but any future changes won't be reflected (you probably don't need that anyway since you save the XML file when clicking 'Save').
As for the chain in between curly braces, {components.CreateCharacters.mainchar.text} does not seem correct because components.CreateCharacters is a class reference, and not the reference to the component directly. Instead you should use creatchr;
I am not sure if the variable replacement inside XML supports .. Have you tried saving the text value inside a local or a class variable like this ?
var currentText:String = creatchr.mainchar.text;
<TXT>{currentText}</TXT>
I have one MXML File as
<objecthandles:ObjectHandles xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" backgroundAlpha="1" xmlns:mx="library://ns.adobe.com/flex/mx"
allowRotate="true" minHeight="25" minWidth="60" height="100" width="200">
<s:BorderContainer id="borderCon" width="100%" height="100%" minHeight="25" minWidth="60"
backgroundAlpha="0" borderVisible="false" borderAlpha="0">
<s:HGroup id="hgText" width="100%" height="100%" gap="0" >
<mx:TextArea id="txtAdd" width="100%" height="100%" color="black"
minHeight="25" minWidth="60" horizontalScrollPolicy="off" verticalScrollPolicy="off" focusOut="txtAddKeyUpHandler(event)"
keyUp="txtAddMirrorKeyUpHandler(event)"
creationComplete="onTextCreationComplete()" />
</s:HGroup>
</s:BorderContainer>
</objecthandles:ObjectHandles>
When ever i create the object of the Fileas
var txtElement:TextElement = new TextElement();
txtElement.txtAdd.text = "Hello";
Then it showing the null object reference that
txtElement.txtAdd seems to be null
Need Perfect Solution?
In the Flex component lifecycle subcomponents will not be created until the parent component is added to the displaylist. Only when the component is added to the displaylist and fully built, will you be able to access its subcomponents. When the component is completely ready for usage, it will dispatch a FlexEvent.CREATION_COMPLETE event.
So do something like this:
var txtElement:TextElement = new TextElement();
txtElement.addEventListener(FlexEvent.CREATION_COMPLETE, initTxtElement);
addElement(txtElement);
private function initTxtElement(event:FlexEvent):void {
txtElement.txtAdd.text = "Hello";
}
Or better yet, since it's a custom component: expose the 'text' property as a property of 'TextElement' and handle the deferred setting of the property internally, so that you can write: txtElement.text = "hello".
I am adding a tab navigator to a title window here. Once the title window is closed, it can be reopened using the button.But on opening the title window second time in this manner ,the content of the children of the Tab navigator(here, a label) is not visible.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"
<mx:TabNavigator x="68" y="68" width="200" height="200" id="tabNavig" historyManagementEnabled="false">
</mx:TabNavigator>
<mx:Script>
<![CDATA[
import mx.events.CloseEvent;
import mx.managers.PopUpManager;
public function init():void{
tabNavig.removeAllChildren();
tabNavig.addChild(canvas1);
tabNavig.addChild(canvas2);
tabNavig.addChild(canvas3);
expenseTitle.showCloseButton = true;
expenseTitle.addChild(tabNavig);
PopUpManager.addPopUp(expenseTitle,this,false);
expenseTitle.addEventListener(CloseEvent.CLOSE,titleWindow_close);
}
private function titleWindow_close(evt:CloseEvent):void
{
expenseTitle.removeAllChildren();
PopUpManager.removePopUp(expenseTitle);
}
]]>
</mx:Script>
<mx:TitleWindow id="expenseTitle" >
</mx:TitleWindow>
<mx:Canvas id="canvas1" x="476" y="117" width="200" height="200" >
<mx:Label x="64" y="93" text="Label1"/>
</mx:Canvas>
<mx:Canvas id="canvas2" x="244" y="310" width="200" height="200" >
<mx:Label x="111.5" y="29" text="Label2"/>
</mx:Canvas>
<mx:Canvas id="canvas3" x="697" y="117" width="200" height="200" >
<mx:Label x="59" y="79" text="Label3"/>
</mx:Canvas>
<mx:Button x="78" y="310" label="Button" click="init()"/>
</mx:Application>
The structure of your MXML is completely wrong.
You need to keep MXML components (e.g. a TitleWindow that you plan on using as a popup) separate from your main application markup.
For example, create a separate MXML component, called MyForm.mxml. This component should be a TitleWindow with a Tab Navigator. The Tab Navigator should have the 3 Canvas components as children.
Then, in your main application logic, the Button should launch the pop up, MyForm.mxml like so:
var form:MyForm = MyForm(PopUpManager.createPopUp(this, MyForm, true));
PopUpManager.centerPopUp(MyForm);
Finally, in your MyForm.mxml component, add the event listener for closing. The method should only need to call: PopUpManager.removePopUp(this);
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.
I need to call a component named "defectTracker.mxml" by clicking a link in another mxml component called "reviewComponent.mxml". How do I achieve that?
This is my reviewComponent.mxml code:
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
width="100%" height="100%"
horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Script>
<![CDATA[
private function defectTrackerLink(event:Event):void{
//call defectTracker
}
]]>
</mx:Script>
<mx:LinkButton label="Delete" textDecoration="underline" textRollOverColor="blue"/>
<mx:LinkButton label="Defect Tracker" textDecoration="underline" textRollOverColor="blue" click="defectTrackerLink(event)"/>
</mx:VBox>
Some one guide me.
Main.mxml:
<mx:Script>
<![CDATA[
private function subBtnBar(evt:ItemClickEvent):void{
switch (evt.label){
case "IQA/UAT":
this.bdyStack.selectedChild = screenIQA;
break;
case "EQA":
Alert.show("Yet To Design");
break;
case "Review Tracker":
this.bdyStack.selectedChild = reviewTracker;
break;
case "Defect Tracker":
this.bdyStack.selectedChild = defectTracker;
break;
default:
trace ("Neither a or b was selected")
}
}
]]>
</mx:Script>
<mx:ViewStack id="tabView" width="910" creationPolicy="all">
<mx:ToggleButtonBar horizontalGap="0" id="subTabBar"
itemClick="subBtnBar(event);" styleName="SubButtonBar"
hideEffect="{dissolveOut}" showEffect="{dissolveIn}">
<mx:dataProvider>
<mx:String>IQA/UAT</mx:String>
<mx:String>EQA</mx:String>
<mx:String>Review Tracker</mx:String>
<mx:String>Defect Tracker</mx:String>
<mx:String>Defect Configuration</mx:String>
<mx:String>Defect Export</mx:String>
<mx:String>Defect Import</mx:String>
</mx:dataProvider>
</mx:ToggleButtonBar>
</mx:ViewStack>
<mx:ViewStack id="bdyStack" width="910" height="80%">
<components:ScrIQA id="screenIQA"
hideEffect="{dissolveOut}" showEffect="{dissolveIn}"/>
<components:scrWorkList id="screenWorkList"
hideEffect="{dissolveOut}" showEffect="{dissolveIn}"/>
<components:DefectEntryVerification id="defectEntryVerification"
hideEffect="{dissolveOut}" showEffect="{dissolveIn}"
width="100%" height="100%"/>
<components:scrDefectResolutionAndCause id="defectResolutionnVerification"
hideEffect="{dissolveOut}" showEffect="{dissolveIn}"
width="100%" height="100%"/>
<components:reviewTracker id="reviewTracker"
hideEffect="{dissolveOut}" showEffect="{dissolveIn}"
width="100%" height="100%"/>
<components:defectTracker id="defectTracker"
hideEffect="{dissolveOut}" showEffect="{dissolveIn}"
width="100%" height="100%"/>
</mx:ViewStack>
The defect Tracker scren is already linked with the main mxml file. How to call the function in the reviewComponent file?
reviewComponent consist of 2 link buttons and it is a column entry of the reviewTracker.mxml file's datagrid. So when I click the link in the review component, I want the defectTracker screen to be called. Its already a child of the main.mxml file.
I tried creting an instance of the main file in the component, and changes the selected child to defect tracker, It shows an error saying:
Error #1009: Cannot access a property or method of a null object reference.
My modified reviewComponent.mxml code:
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
width="100%" height="100%"
horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Script>
<![CDATA[
private function defectTrackerLink(event:Event):void{
var main:Main=new Main();
main.bdyStack.selectedChild=main.defectTracker; }
]]>
</mx:Script>
<mx:LinkButton label="Delete" textDecoration="underline" textRollOverColor="blue"/>
<mx:LinkButton label="Defect Tracker" textDecoration="underline" textRollOverColor="blue" click="defectTrackerLink(event)"/>
</mx:VBox>
Please some one guide me in this? Should I call the item click event function of the Toggle button Bar? If so how to do It?
I would use a custom event that bubbles. You would dispatch it from the reviewComponent and it would be caught by the defectTracker.
Here are some good articles that tell you how to create a custom event and how to use it http://livedocs.adobe.com/flex/3/html/help.html?content=createevents_3.html
http://www.connatserdev.com/blog/?p=86
By calling, do you mean adding it to the VBox?
var dTracker:DefectTracker = new DefectTracker();
addChild(dTracker);
Would calling is with a popup work?
var dTracker:DefectTracker = new DefectTracker();
PopUpManager.addPopUp(dTracker, this, true);