Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Results 1 to 6 of 6

Thread: attachMovie...removed !

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

    attachMovie...removed !

    amazing Flash templates
    zzup :P
    As we"ve seen, the difference between AS 2 and AS 3 are not just a few, actually I"d say they are many and deep.
    The attachMovie method has been removed, therefore I"ll explain how to "attach" a MovieClip via a linkage of the library and we"ll see that it is simple and it shows the beauty of Object Oriented Programming.
    I create my FLA and I call it "attach_me".
    I create a MovieClip and I call it "mc_clip".
    I create a MovieClip inside mc_clip and I call it "mc_dot".
    Now I create the Document Class (the Main Class):
    Code:
    package
    {
    	import flash.display.MovieClip;
    	
    	public class AttachMe extends MovieClip
    	{
    		public function AttachMe()
    		{
    			stage.frameRate=24;
    			
    			var clip:Clip=new Clip();
    			this.addChild(clip);
    		}
    	}
    }
    and I save the AS file as "AttachMe" (always called as the class"always!).
    Don"t let the line var clip:Clip=new Clip(); scare you; now we"ll see who Clip is.

    I create another class called "Clip" and I save it in the same folder holding attach_me.fla and AttachMe.as:
    Code:
    package
    {
    	import flash.display.MovieClip;
    	import flash.events.*;
    	
    	public class Clip extends MovieClip
    	{
    		private var spring:Number=.1;
    		private var center:Number;
    		private var vel_x:Number=0;
    		
    		public function Clip()
    		{
    			this.center=this.width/2;
    			this.initEvent();
    		}
    		
    		public function initEvent():void
    		{
    			this.dot_mc.x=this.vel_x;
    			this.dot_mc.y=this.height/2;
    			this.dot_mc.addEventListener(Event.ENTER_FRAME,bounding);
    		}
    		
    		public function bounding(event:Event):void
    		{
    			var acc_x:Number=(this.center-this.dot_mc.x)*this.spring;
    			this.vel_x+=acc_x;
    			this.dot_mc.x+=this.vel_x;
    		}
    	}
    }
    Let"s go back to the FLA and:
    Right-click on mc_clip in the library, follow linkage and the famous window (where in Flash 8 you used to put the name reference to export the MovieClip with Actionscript) opens.
    Let"s activate the option " Export for Actionscript " and 2 text fields become available:
    Class
    Base class
    In Class I put : Clip (we"ll see why later), while I leave Base class as it is.

    Now, inside the Clip class, the " this " is exactly referencing the MovieClip "mc_clip" we"re initiating ( vulgarly said to be "attached") from the library.

    I launch the swf:








    As we can see, inside the Clip class, I call this.dot_mc , dot_mc is in fact a child of mc_clip in the library..
    This shows that, even who"s not very familiar with coding, once the MovieClip is initialized from the library via the linkage, we can have anything we like inside it and easily accessible.

    Until next time !

  2. #2
    Junior Member Settled In bhatushai is on a distinguished road
    Join Date
    Feb 2008
    Posts
    7
    Rep Power
    0

    Re: attachMovie...removed !

    how to put in multiple dot? i have tried modifying your code but still no result

  3. #3
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,457
    Rep Power
    8

    Re: attachMovie...removed !

    Hi,
    do you mean using a loop ?

  4. #4
    Junior Member Settled In bhatushai is on a distinguished road
    Join Date
    Feb 2008
    Posts
    7
    Rep Power
    0

    Re: attachMovie...removed !

    i was thinking like using an array for attaching multiple mc_dot. how to do that with this code?

  5. #5
    Junior Member Settled In fathed is on a distinguished road
    Join Date
    Apr 2008
    Posts
    1
    Rep Power
    0

    Re: attachMovie...removed !

    Hi.

    Yes, how would we use a loop with this?

  6. #6
    Member Settled In manheman is on a distinguished road
    Join Date
    Sep 2007
    Posts
    38
    Rep Power
    0

    Re: attachMovie...removed !

    Hello Flep,
    I try to make the same thing but i didn't succeed.
    So can you post me a zip with files ???
    Thaks a lot.

+ Reply to Thread

Similar Threads

  1. swapDepths removed !
    By Flep in forum Tutorials
    Replies: 2
    Last Post: 07-08-08, 20:24
  2. loadMovie...removed !
    By Flep in forum Tutorials
    Replies: 3
    Last Post: 07-07-08, 22:40
  3. onRelease...removed !
    By Flep in forum Tutorials
    Replies: 2
    Last Post: 20-11-07, 11:15
  4. DuplicateMovieclip...removed!
    By Flep in forum Tutorials
    Replies: 0
    Last Post: 27-09-07, 13:04
  5. attachMovie and co
    By tatone7602 in forum Actionscript 3.0 base
    Replies: 6
    Last Post: 27-08-07, 09:22

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

Search Engine Optimization by vBSEO