/ Published in: ActionScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//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); } } }