EventDispatcherってなんぞ?
♥0 |
Line 45 |
Modified 2010-02-17 00:11:18 |
MIT License
archived:2017-03-20 11:26:15
ActionScript3 source code
/**
* Copyright ug24k8 ( http://wonderfl.net/user/ug24k8 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/1n6M
*/
package
{
import com.bit101.components.*;
import flash.display.*;
import flash.text.*;
import flash.events.Event;
[SWF(width="400", height="300",
backgroundColor="0xffcfcf", frameRate="12")]
public class EdispatchTest extends Sprite
{
private var btn_:PushButton;
public function EdispatchTest():void
{
btn_ = new PushButton(stage, 10, 20, "Test");
var text:TextField = new TextField();
text.type = TextFieldType.DYNAMIC;
text.x = 10;
text.y = 80;
text.border = true;
addChild(text);
var e:EventDispatchTest = new EventDispatchTest(btn_);
e.addEventListener(EventDispatchTest.PUSH, onPushHandler);
function onPushHandler(e:Event):void{
text.text = "ok!";
}
}
}
}
import com.bit101.components.*;
import flash.events.*;
import flash.display.*;
class EventDispatchTest extends EventDispatcher {
public static const PUSH:String = "push_btn";
private var btn_:PushButton;
public function EventDispatchTest(btn:PushButton):void {
btn_ = btn;
init();
}
private function init():void {
btn_.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
}
private function onMouseDownHandler(e:MouseEvent):void {
dispatchEvent(new Event(PUSH));
}
}