Revision: 41764
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 23, 2011 05:02 by dareng
Initial Code
//MAIN.as package { import flash.display.MovieClip; import flash.events.MouseEvent; import flash.events.Event; public class Main extends MovieClip{ //public static const customEvent:String = "customEvent"; public function Main() { // constructor code var ball:Ball = new Ball(this); addChild(ball);ball.x = 100; ball.y = 100; ball.addEventListener("my event", listenForClick); } // listening to the ball private function listenForClick (evt:Event) : void { trace("i hear it"+evt.target); evt.target.alpha = .4; } // run from the ball public function init (passed:String) : void { trace("initalise "+passed); } } //BALL.as package { import flash.display.MovieClip; import flash.events.MouseEvent; import flash.events.Event; public class Ball extends MovieClip{ private var ballVar:String = "ochie"; private var targ:MovieClip; public function Ball(tt:MovieClip) { // constructor code targ = tt; stop(); buttonMode = true; addEventListener(MouseEvent.MOUSE_OVER, ball_over); addEventListener(MouseEvent.MOUSE_OUT, ball_out); addEventListener(MouseEvent.CLICK, ball_clicked); } private function ball_over (e:MouseEvent) : void { gotoAndStop(2); } private function ball_out (e:MouseEvent) : void { gotoAndStop(1); } private function ball_clicked (e:MouseEvent) : void { trace("clik"); dispatchEvent(new Event("my event")); targ.init(ballVar); } } }
Initial URL
Initial Description
Initial Title
Custom event listener example
Initial Tags
Initial Language
ActionScript