Friday, 26 June 2009

onEnterFrame in Actionscript 3

The onEnterFrame in Actionscript 3.0 is different to the Actionscript 2.0 version. In the AS3 version you need to add an event listener to the onEnterFrame method. Below I have shown a comparison of the two onEnterFrame versions.

AS2

onEnterFrame = function(){
//Your actions here
}


AS3

addEventListener(Event.ENTER_FRAME,myEnterFrame);
function myEnterFrame(event:Event) {
//Your actions here
}


As you can see above both the Actionscript versions are very similar. In AS3 you need to add an additional line of code which is the event listener method. Apart from this extra event listener code the way you of implement the onEnterFrame is exactly the same.

The onEnterFrame is called repeatedly at the same frame rate as the SWF file. For example, if you add following code into the actionpanel. Then the “onEnterFrame called” message will be called repeatedly and you will see a long list of these messages.

addEventListener(Event.ENTER_FRAME,myEnterFrame);
function myEnterFrame(event:Event) {
trace ("onEnterFrame called");
}

0 comments:

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP