flash on 2010-1-4
外部クラスから、Main(SimpleDemo)へ、addEventListenerするテスト
/**
* Copyright narutohyper ( http://wonderfl.net/user/narutohyper )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/eY15
*/
package {
import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
[SWF(width = 465, height = 465, frameRate = 60)]
/*
外部クラスから、Main(SimpleDemo)へ、addEventListenerするテスト
*/
public class SimpleDemo extends Sprite {
public var test:Sprite
public var n:Boolean=false
public function SimpleDemo():void {
this.buttonMode=true;
this.useHandCursor=true;
test=new Sprite()
test.graphics.beginFill(0xFF0000,1)
test.graphics.drawRect(0,0,200,200)
this.addChild(test)
var sp:sample=new sample(this);
trace('CLICK');
}
public function hoge(e:MouseEvent):void {
if (n==false) {
test.graphics.beginFill(0x0000FF,1)
n=true
} else {
test.graphics.beginFill(0xFF0000,1)
n=false
}
test.graphics.drawRect(0,0,200,200)
}
}
}
import flash.display.Sprite;
import flash.events.MouseEvent;
class sample extends Sprite{
public function sample(mc:SimpleDemo) {
mc.addChild(this)
mc.addEventListener(MouseEvent.CLICK,mc.hoge)
mc.addEventListener(MouseEvent.MOUSE_OVER,hoge)
mc.addEventListener(MouseEvent.MOUSE_OUT,hoge2)
function hoge(e:MouseEvent):void {
mc.test.alpha=0.5
}
function hoge2(e:MouseEvent):void {
mc.test.alpha=1
}
}
}