Using AsBroadcaster with buttons on the stage

![Adobe Flash](/blog/wp-content/uploads/icons/Flash.jpg)

The following technique is a quick and easy way of triggering methods of a class from a physical button on the stage.

[as]
import mx.events.EventDispatcher;
import mx.utils.Delegate;
class SampleClass extends MovieClip {

// Declare objects on stage
var navigation_mc:MovieClip;

function SampleClass()
{
AsBroadcaster.initialize(this.navigation_mc);
this.navigation_mc.addListener(this);
this.navigation_mc.item1_btn.onRelease = function (){ this._parent.broadcastMessage(”NavItemRelease”,”item1″); }
this.navigation_mc.item2_btn.onRelease = function (){ this._parent.broadcastMessage(”NavItemRelease”,”item2″); }
this.navigation_mc.item3_btn.onRelease = function (){ this._parent.broadcastMessage(”NavItemRelease”,”item3″); }
}

function NavItemRelease(itemID){
trace(”Navigation Item “+itemID+” was selected.”);
}
}
[/as]

Post a Comment

Your email is never shared. Required fields are marked *

*
*