6/14/2010 1:45:28 AM
Title:
how to access specific contianers from custom comps
hi all,
i am instantiating one component from main application, comp contains one image ,1 text box and 1 button
i want to image and text box of comp in one location of the application and
image and button at another location
but once once i import the component i am unable access specific containers.
i have tried using visible property too
thanks
6/14/2010 1:51:55 AM
declare a public var inside componnent and set the image id to that variable. The public varible should be accessible from out side. Fpr e.g
inside your component (myComponent)
//actionscript
public var buttoon=myButton;
//mxml
<mx:Button id= "myButton"
now it should be accessible using
myComponent.buttoon.visible= true;
6/14/2010 2:16:28 AM
hi derek not working,here is my code
comp:
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
[Bindable]
private var _spotSource:String;
[Bindable]
private var _descriptionTxt:String;
[Bindable]
private var _spotName:String;
public var button:Button=productButton;
public var textbox:TextInput=descBox;
public function set imagePath(str:String):void{
_spotSource = str;
}
public function set description(str:String):void{
_descriptionTxt = str;
}
public function set productName(str:String):void{
_spotName = str;
}
]]>
</mx:Script>
<mx:Image source="{_spotSource}" width="100" height="100"/>
<mx:TextInput id="descBox" text="{_descriptionTxt}" width="275" height="100%" backgroundColor="0xEEEEEE"/>
<mx:Button id="productButton" label="{_spotName}" width="100" height="100"/>
</mx:HBox>
my main app:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()" >
<mx:Script source="as/myAppAS.as"/>
<mx:HTTPService id="categoryService" url="data/content.xml" resultFormat="e4x" result="resultHandler(event)" fault="faultHandler(event)"/>
<mx:Box id="spotsContainer" horizontalScrollPolicy="off" width="400" x="590"
height="{(secondTabVisible) ? 250 : 280}" y="{(secondTabVisible) ? 70 : 40}" >
<mx:Repeater id="spotsRepeater" dataProvider="{spotsListCollection}">
<comps:Spot imagePath="{(spotsRepeater.currentItem).@mediahubthumbnail}"
description="{(spotsRepeater.currentItem).@description}" click="myEventHandler(event)"/>
</mx:Repeater>
</mx:Box>
<mx:Box id="gallery1" height="115" width="700" y="384" verticalAlign="middle" horizontalAlign="center"
horizontalGap="0" x="10">
<mx:HBox>
<mx:Repeater id="spotsRepeater1" dataProvider="{spotsListCollection}">
<comps:Spot imagePath="{(spotsRepeater1.currentItem).@mediahubthumbnail}"
productName="{(spotsRepeater1.currentItem).@spotname}" textbox.visible=false />
</mx:Repeater>
</mx:HBox>
</mx:Box>
</mx:Application>
thanks buddy
6/14/2010 5:44:43 AM
after reviewing your code I can see that you are using
"textbox.visible=false" inside a component tag , that's not the right place to place the code . Its not a property of component so cannot be inside tag. It can be accessed in the script function only. You can visible hide it inside script on some event like button click.
To access it inside TAG use it like property first declare a public property inside your component like this :
//function inside component to set the visibility of textBox
public function set textBoxVisibility(val:Boolean):void{
textbox.visible = val;
}
// now in main mxml you can use it like this :
<comps:Spot id="myComp" imagePath="{(spotsRepeater1.currentItem).@mediahubthumbnail}"
productName="{(spotsRepeater1.currentItem).@spotname}" textBoxVisibility="false" />
I hope it works for you , let me know