5/13/2010 5:33:47 AM
Title:
how to access custom properties
hi all,
i have one application with many sub components
1. i want to know how to access the properties of component into another component
2.if i want to call a method of a component by clicking a button from the main application ,what should i provide to click event : click=" ? "
guys plz help , i am struggling with the basics
5/13/2010 5:59:31 AM
Can you please elaborate more on your question? Or you can copy paste what you have coded and give more collaborative description on what you are expecting.
5/13/2010 6:00:01 AM
*collaborative = elaborative
5/13/2010 6:13:25 AM
to access the properties of a component in another you should have its reference. Say you have a textBox with id myText in your main mxml file . And you want to access it from some other component you can access access its text property :
//code inside any other component
trace(Application.application.myText)
here Application.application refers to your application root and whatever is there public will be accessible and its properties also.
2)To access a public method
Say a public method (getmyValue) of component i.e myComponent can be accessed using
click"myComponent.getmyValue();"
5/13/2010 6:16:18 AM
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlns:v="components.*" creationComplete="pecdata.send()">
<mx:Script>
<![CDATA[
import components.ContactusForm;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
public var mycoll: XMLListCollection;
private function resultHandler(event:ResultEvent):void{
var dp:Object=event.result as XML;
}
private function handleFault(event:FaultEvent):void{
trace(event.fault.faultCode+":"+event.fault.faultString);
}
]]>
</mx:Script>
<mx:HTTPService id="pecdata" url="peccontentdata.xml" result="resultHandler(event)"
fault="handleFault(event)" resultFormat="e4x"/>
<mx:XMLListCollection id="peccoll" source="{pecdata.lastResult.pectab}"/>
<v:MyComp id="tabandvideo" width="957" height="100%" x="56" y="107" verticalAlign="middle"/>
<v:ContactusForm x="57" y="109" height="491"/>
<v:AskaquestionForm x="57" y="118" width="957" height="100%"/>
<v:ImageScroll x="57" y="415" width="475" height="86"/>
<mx:ControlBar cornerRadius="10" fontSize="12" color="#344C51" fontWeight="bold" y="726" x="56" width="957">
<mx:Label text="Ask A Question" click=""/>
<mx:Label text="|" width="13"/>
<mx:LinkButton label="Contact Us" click=""/>
<mx:Label text="|" width="13"/>
<mx:Label text="Education Center Home" click=""/>
<mx:Label text="|" width="13" height="20"/>
<mx:Label text="Schedule Appointment" click=""/>
</mx:ControlBar>
</mx:Application>
-----------------------------cust component
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:v="components.*" height="300"
horizontalScrollPolicy="off">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.collections.XMLListCollection;
import mx.controls.Alert;
import mx.core.Application;
[Bindable]
private var dp:Object = Application.application.peccoll;
[Bindable]
private var obj:String;
private function myEventHandler(event:MouseEvent):void {
obj = ((event.currentTarget).getRepeaterItem().@mediahubfile);
}
]]>
</mx:Script>
<mx:VideoDisplay id="vid" source="{obj}" autoPlay="true" width="50%" height="320" bufferTime="0.1"/>
<mx:Panel paddingTop="1" width="50%" height="320" cornerRadius="10" paddingRight="1" borderColor="#CBDDF8" backgroundAlpha="0.3"
verticalScrollPolicy="off">
<mx:TabNavigator id="pectabn" width="100%" height="100%" tabHeight="40" horizontalGap="5">
<mx:Repeater id="rp" dataProvider="{dp}">
<mx:VBox id="rpbox" label="{rp.currentItem.@pectabname}" >
<mx:Repeater id="rp2" dataProvider="{rp.currentItem.spotdetails}">
<mx:HBox horizontalGap="8">
<mx:Image id="img" source="{rp2.currentItem.@mediahubthumbnail}" click="myEventHandler(event)"/>
<mx:TextArea id="desc" text="{rp2.currentItem.@description}" click="myEventHandler(event)"
editable="false" cornerRadius="10" selectable="false" wordWrap="true" width="100%"/>
</mx:HBox>
</mx:Repeater>
</mx:VBox>
</mx:Repeater>
</mx:TabNavigator>
<mx:ControlBar>
<mx:Text text="PLAY:Select thumbnail above to preview spot."/>
</mx:ControlBar>
</mx:Panel>
</mx:HBox>
i am building the site with flex and my own images
more details : http://www.ylysnetworks.com/testpec/
Davis
Points: 780
Posts:0
5/13/2010 7:35:21 AM
your functions should be public if you want to access them from other parts of application.
5/13/2010 10:01:32 AM
if MyComp is your custom component then you can access the components inside your MyComp using MyComp.vid which are public , but if you want to access dataProvider like dp then you should make it public first
public var dp:Object = Application.application.peccoll;
if you want to access Mycomp from ContactusForm you can use script like
parent.document.Mycomp or Application.application.Mycomp or parent.Application.Mycomp