This is a discussion on onEnterFrame with Flash CS3 within the Tutorials forums, part of the Flash English category; Some of you may have worried that the MovieClip onEnterFrame method had been removed. Unfounded worry, in that it has ...
Some of you may have worried that the MovieClip onEnterFrame method had been removed.
Unfounded worry, in that it has in fact been optimized and not removed, but the way to use it has changed.
With AS 2.0 all you needed to do was: nomeMovieClip.onEnterFrame=function, with AS 3.0 this doesn"t apply anymore.
How to do it, then" I"ll explain"
I create an FLA and save it as " onEF.fla " .
I create 3 MovieClips , 2 round ones and 1 rectangular.
I call them clip_0_mc, clip_1_mc, clip_2_mc respectively.
I create the Document Class, an AS file that I save as " Prova.as " and I write:
The result:Code:package { package { import flash.display.MovieClip; import flash.events.Event; public class Prova extends MovieClip { private var boo:Boolean=true; public function Prova() { initListeners(); } private function initListeners():void { clip_0_mc.addEventListener(Event.ENTER_FRAME,muoviDueClips); clip_0_mc.addEventListener(Event.ENTER_FRAME,muoviLaTerzaClip); } private function muoviDueClips(e:Event):void { clip_0_mc.visible=boo; clip_1_mc.rotation--; boo=!boo; } private function muoviLaTerzaClip(e:Event):void { clip_2_mc.rotation++; } } } }
In this example we can understand that, whilst in AS 2.0 you"d call functions from an interval like so:
with AS 3.0 we associate a listener to the MovieClip, passing 2 parameters: an event ( in this case ENTER_FRAME ) and the name of the function to call.Code:my_mc.onEnterFrame=function():Void { chiamaUno() chiamaDue(); } function chiamaUno():Void { //codice da eseguire } function chiamaDue():Void { //codice da eseguire }
All of this is much cleaner, in respect of good Object Oriented Programming standard and you can call multiple functions.
Stay tuned !
Last edited by Flep; 28-08-08 at 05:53.
Bookmarks