action script:
package oreilly.cookbook
{
import mx.core.Application;
import mx.containers.Canvas;
import flash.events.Event;
public class CodeBehindComponent extends Canvas
{
public function CodeBehindComponent()
{
super();
addEventListener(Event.ADDED_TO_STAGE, addedToStageListener);
}
protected function addedToStageListener(event:Event):void
{
trace(" Added to Stage from Code Behind ");
}
protected function clickHandler(event:Event):void
{
trace(" Click handled from component "+event.target);
}
}
}
component:
<?xml version="1.0" encoding="utf-8"?>
<cookbook:CodeBehindComponent xmlns:cookbook="oreilly.cookbook.*" xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
<mx:Button label="Button" x="10" y="10" click="clickHandler(event);"/>
</cookbook:CodeBehindComponent>
application:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:cookbook="oreilly.cookbook.*" xmlns:ns1="*">
<ns1:CodeBehindComponent x="10" y="10">
</ns1:CodeBehindComponent>
</mx:Application>