Main.as


package

{

import flash.display.Sprite;

import flash.events.MouseEvent;

import flash.geom.Point;


  [SWF( frameRate = "30", width="500", height="500", backgroundColor="0xffffff")]

public class Main extends Sprite

{

private var _a:A;

private var _b:B;

public function Main()

{

setting();

}

private function setting():void

{

_a = new A();

addChild(_a);

_b = new B();

_b.bClick = onBSet;

_a.addChild(_b);

}

private function onBSet( $point:Point ):void

{

trace(_b.x, _b.y);     // x : 0, y : 0

trace($point.x, $point.y); // x : 100, y : 100

}

}

}




A.as


package

{

import flash.display.Sprite;


public class A extends Sprite

{

public function A()

{

super();

graphics.beginFill(0x000000, 1);

graphics.drawRect(0, 0, 300, 300);

graphics.endFill();

x = 100;

y = 100;

}

}

}





B.as


package

{

import flash.display.Sprite;

import flash.events.MouseEvent;

import flash.geom.Point;

public class B extends Sprite

{

public function B()

{

super();

graphics.beginFill(0xff0000, 1);

graphics.drawRect(0, 0, 100, 100);

graphics.endFill();

addEventListener( MouseEvent.CLICK, onClick );

}

public var bClick:Function;

protected function onClick(e:MouseEvent):void

{

var globalPoint:Point = this.localToGlobal( new Point( 0, 0 ) );

if(bClick != null) 

bClick( globalPoint );

}

}

}

'ActionScript3.0 > As3.0' 카테고리의 다른 글

CallBack Function  (0) 2013.03.14
상속  (0) 2013.03.14
Function 전달.  (0) 2013.03.06
Function 참조.  (0) 2013.03.04
FLV 재생의 원리.  (3) 2010.09.02

+ Recent posts