How to get an ID or a variable from the WindowedApplication to the Component?
Not sure exactly what you're trying but possibly
outerApplication.variablename may work if you've declared the variable public.
Another way is to declare a component variable as public
and then set it to the Application var value when you're opening the component.
I've used this with Popup components.
thanks for reply.
but again i want ID from Window to component.
here is my .mxml file-->
<mx:Window
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="onCreationComplete()"
>
<mx:Button x="100" y="70" label="Ok" click="controller.Button_clickHandler(event)"/>
<mx:Label x="29" y="43" text="New Folder:"/>
<mx:TextInput id="textIP" x="114" y="42"/>
</mx:Window>
And my ActionScript file is-->
public class AppController
{
public function Button_clickHandler(event:MouseEvent):void
{
//here how to get id "textIP" defined in .mxml file.
}
}
If you have to rely upon it a lot, you best investigate the event system a bit more or look at frameworks like Robotlegs or Mate. However, for a quick one-off, you can use FlexGlolbals.topLevelApplication.myVariable just about anywhere, if the main class has that variable publicly defined.
Here's my amazing app:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:ns1="*"
width="300" height="300" minWidth="300" minHeight="300" creationComplete="init()">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<![CDATA[
public var myVariable:String;
private function init():void{
myVariable = "Hello World";
}
]]>
</fx:Script>
<ns1:myComponent horizontalCenter="0" verticalCenter="-31">
</ns1:myComponent>
</s:Application>
and my equally cool component
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.core.FlexGlobals;
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button x="0" y="0" label="Say Hello" click="{Alert.show(FlexGlobals.topLevelApplication.myVariable)}"/>
</s:Group>
I believe it will work if you use a two-way public variable (if that's in 3.4???) in the value attribute of your text component.
But you need to reference the 'variable name' (as in the provided example) not the text component id.
So you'd change your text component declaration to
<mx:TextInput id="textIP" text=@"{myvariable}" x="114" y="42"/>
and still use the button call
<s:Button x="0" y="0" label="Say Hello" click="{Alert.show(FlexGlobals.topLevelApplication.myVariable)}"/>
or for 3.4
<s:Button x="0" y="0" label="Say Hello" click="{Alert.show(Application.application.myVariable)}"/>
North America
Europe, Middle East and Africa
Asia Pacific