Using Code-behind with Flex
Installed Ensemble Tofino (With SDK)
This was my MXML file:
<?xml version="1.0" encoding="utf-8" ?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Button x="45" y="33" label="Say Hello!" click="HelloWorld.click(event)"/>
</mx:Application>
And the .AS file was:
package
{
import flash.events.Event;
import flash.events.MouseEvent;
import mx.controls.Alert;
public class HelloWorld
{
public static function click(event:MouseEvent)
{
Alert.show("This responded to an event from code-behind");
}
}
}
Ideally, The Application Class should inherit from HelloWorld, so that the click event could be protected rather than
static; so it should be modified as follows:
<?xml version="1.0" encoding="utf-8" ?>
<my:HelloWorld xmlns:my="*"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Button x="45" y="33" label="Say Hello!" click="click(event)"/>
</my:HelloWorld>
and the AS file thus:
package
{
import flash.events.Event;
import flash.events.MouseEvent;
import mx.controls.Alert;
import mx.core.Application;
public class HelloWorld extends Application
{
protected function click(event:MouseEvent)
{
Alert.show("This responded to an event from code-behind");
}
}
}