Reputation: 25
I am creating an AIR application, The mainapp.mxml has a button and VBOX. When clicked on button, child.mxml should be displayed in VBOX.
Would appreciate if the code is in flex also , as it would be easy for me to modify the tags.
can anyone help me how to do it please! Thanks in advance
Upvotes: 0
Views: 202
Reputation: 5874
If you're using Flex 4, you could also use states
to handle this. The button would simply change the state, and the VBox would be included in whichever state you're setting:
<fx:Script>
<![CDATA[
private function changeState():void {
currentState = (currentState == "default") ? "showVBox" : "default";
}
]]>
</fx:Script>
<s:states>
<s:State name="default" />
<s:State name="showVBox" />
</s:states>
<mx:VBox id="myVBox" includeIn="showVBox" />
<mx:Button label="Show/Hide VBox" click="changeState()" />
In my example, clicking the button simply swaps the state between "default" and "showVBox". This allows the player to add/remove the VBox for you, rather than worrying about doing it yourself.
Disclaimer: I haven't tested the above code, so the namespaces could be off :)
Upvotes: 0
Reputation: 16085
Add a click handler to the button, in that handler create an instance of child and add it to the VBox:
<mx:Button id="myButton" label="My Button" click="myButton_clickHandler(event)"/>
And the handler:
function myButton_clickHandler(event:Event):void {
var child:Child = new Child();
myVBox.addChild(child);
}
Upvotes: 1