Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

attachMovie...removed !

This is a discussion on attachMovie...removed ! within the Tutorials forums, part of the English Forums category; zzup :P As we"ve seen, the difference between AS 2 and AS 3 are not just a few, actually ...


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 12-10-07, 17:17
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,446
Rep Power: 6
Flep is on a distinguished road
attachMovie...removed !

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 !
__________________

 


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:32..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 03-03-08, 07:53
Junior Member
 
Join Date: Feb 2008
Posts: 5
Rep Power: 0
bhatushai is on a distinguished road
Re: attachMovie...removed !

how to put in multiple dot? i have tried modifying your code but still no result
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #3 (permalink)  
Old 03-03-08, 07:59
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,446
Rep Power: 6
Flep is on a distinguished road
Re: attachMovie...removed !

Hi,
do you mean using a loop ?
__________________

 


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 !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #4 (permalink)  
Old 05-03-08, 02:25
Junior Member
 
Join Date: Feb 2008
Posts: 5
Rep Power: 0
bhatushai is on a distinguished road
Re: attachMovie...removed !

i was thinking like using an array for attaching multiple mc_dot. how to do that with this code?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #5 (permalink)  
Old 17-04-08, 18:27
Junior Member
 
Join Date: Apr 2008
Posts: 1
Rep Power: 0
fathed is on a distinguished road
Re: attachMovie...removed !

Hi.

Yes, how would we use a loop with this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Flash Multi Gallery
  #6 (permalink)  
Old 19-06-08, 20:39
Member
 
Join Date: Sep 2007
Posts: 37
Rep Power: 0
manheman is on a distinguished road
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.
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
swapDepths removed ! Flep Tutorials 2 07-08-08 20:24
loadMovie...removed ! Flep Tutorials 3 07-07-08 22:40
onRelease...removed ! Flep Tutorials 2 20-11-07 11:15
DuplicateMovieclip...removed! Flep Tutorials 0 27-09-07 13:04
attachMovie and co tatone7602 Actionscript 3.0 base 6 27-08-07 09:22


All times are GMT. The time now is 20:31.


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