Home > Uncategorized > Using Code-behind with Flex

Using Code-behind with Flex

This is a few steps on how to use Code-behind with Flex & Visual Studio 2008.

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&quot;
    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&quot;
    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");
        }
    }
}

Advertisement
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: