Using Flash Builder (Flex 4 SDK) I want to controll my application in an external class, just to make code more organized.
I want to access a button (or any other component) and change its enabled status to disable, for example.
My application MXML looks like
[code="xml"]
<?xml version="1.0"?>
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import myClass;
protected function myButton_clickHandler(event:MouseEvent):void
{
myClass.myFunction(this);
}
]]>
</fx:Script>
<s:Button id="myButton" label="Click Me"
click="myButton_clickHandler(event)"/>
</s:Application>
[code]
and my external class looks like:
[code="as3"]
public class myClass
{
public static function myFunction(application:Object):void{
// disable the button
application.myButton.enabled = false;
}
}
[code]
this way you can access all the components of your mxml application.