+ Reply to Thread
Results 1 to 1 of 1

onEnterFrame with Flash CS3

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 ...

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,762
    Rep Power
    11

    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 !

+ Reply to Thread

Similar Threads

  1. onEnterFrame con Flash CS3
    By Flep in forum Articoli e tutorials
    Replies: 8
    Last Post: 14-07-08, 07:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts