We used delegate or Proxy in actionscript 2.0 when we need to parse parameter to a function click or other event with button.
Now in Actionscipt 3.0 how can we do with this issues?
Ans:We will assign a new class to addEventListener and parse parameter into class method.
the Example like this.
1. Create new as file and save its name buttonEvent.as
2. Write this code
package
{
import flash.events.MouseEvent;
import flash.display.Sprite;
public class buttonEvent extends Sprite
{
var val:String;
public function buttonEvent()
{
}
public var setParam(param:String)
{
val=param;
}
public function clickFn(m:MouseEvent):void
{
//the code When click on this button
trace(val);//Hello All Flash BadAss!
}
public function overFn(m:MouseEvent):void
{
//the code When Roll Over on this button
}
public function outFn(m:MouseEvent):void
{
//the code When Roll Out
}
}
}
3. on main time line add tis code
import buttonEvent;
var bt:buttonEvent = new buttonEvent();
var myBt:Button = new Button();
myBt.addEventListener(MouseEvent.CLICK,bt.clickFn);
myBt.addEventListener(MouseEvent.MOUSE_OVER,bt.overFn);
myBt.addEventListener(MouseEvent.MOUSE_OUT,bt.outFn);
//and then assign any value that we need to use with the button
bt.setParam("Hello All Flash BadAss!");
Good luck!
Hudsadin keox
No comments:
Post a Comment