Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

onEnterFrame with Flash CS3

This is a discussion on onEnterFrame with Flash CS3 within the Tutorials forums, part of the English Forums category; Some of you may have worried that the MovieClip onEnterFrame method had been removed. Unfounded worry, in that it has ...


Go Back   Forum Flash CS3 Flash CS4 > English Forums > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-10-07, 19:32
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,446
Rep Power: 6
Flep is on a distinguished road
onEnterFrame with Flash CS3

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:
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++;
		}
	}
}
}
The result:







In this example we can understand that, whilst in AS 2.0 you"d call functions from an interval like so:
Code:
my_mc.onEnterFrame=function():Void
{
	chiamaUno()
	chiamaDue();
}

function chiamaUno():Void
{
	//codice da eseguire
}
function chiamaDue():Void
{
	//codice da eseguire
}
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.
All of this is much cleaner, in respect of good Object Oriented Programming standard and you can call multiple functions.

Stay tuned !
__________________

 


I recommend: Essential Actionscript 3.0

- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
- I do not reply technicians pvt messages. Open a thread !

Last edited by Flep; 28-08-08 at 06:53..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
onEnterFrame con Flash CS3 Flep Articoli e tutorials 8 14-07-08 08:54


All times are GMT. The time now is 23:03.


Powered by vBulletin versione 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap


FlepStudio
by Filippo Lughi
P.IVA 03605860406