Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

How to refer to a MovieClip placed in library of a loaded SWF?

This is a discussion on How to refer to a MovieClip placed in library of a loaded SWF? within the Tutorials forums, part of the Flash English category; The idea was born from a topic in the FlepStudio’s forum in which a user was in difficulty ...


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

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  2 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 24-09-07, 06:49
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
How to refer to a MovieClip placed in library of a loaded SWF?

The idea was born from a topic in the FlepStudio’s forum in which a user was in difficulty using the logic of my tutorial about the preloader with Flash CS3 .
The difficulty was mainly due to this situation:
- the preloader.fla has a Document Class Loading.as
- prova.fla creates prova.swf. Inside the library of prova.fla we have a MovieClip (clip_mc) associated to a class (Clip.as) and inside this MovieClip, we have another MovieClip named "tavola_mc".
- Loading.as loads prova.swf and once the loading complete, creates an instance of a class Chiama_Clip.as which itself an attachMovie of "clip_mc" placed in library of prova.fla (therefore using the associated class: Clip).*

Once understood the logic of the tutorial about the preloader of FlepStudio, it is not difficult to call that MovieClip and create an instance of it.
But only if this MovieClip does not contain any other object.
Trying to insert another MovieClip (tavola_mc) Flash returns an error and says that it is not able to assign a new property to Clip. As child MovieClips are properties of the parent MoveClip and since Clip.as extends the MovieClip class, the Flash error has left me surprised.* The MovieClip class is dynamic and it can create properties in runtime. But Flash tells me the contrary.

Therefore, we will see in this example how to arrive to attach on stage "clip_mc" but we will also see how to resolve this annoying error given by Flash.*

Let us look at it" I clearly will not repeat the whole logic of the preloader.

Who did not know about it, can see it in this article and can download it from the section downloads.
I will start to the point in which Loading.as finishes to load the external SWF in the function "completato":

Code:
private function completato(event:Event):void
{
	preloader_mc.stopRun();
	addChild(loader);
	var sdsd=MovieClip(loader.content)
	var chiama_clip:Chiama_Clip=new Chiama_Clip(this,sdsd);
}
in this method I create an instance of the Chiama_Clip class and pass it the value of the project"s root (preloader.fla) and the root of the loaded SWF:
var sdsd=MovieClip(loader.content);
var chiama_clip:Chiama_Clip=new Chiama_Clip(this,sdsd);

The Chiama_Clip class is implemented the following way:
Code:
package
{  
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;

	public class Chiama_Clip extends MovieClip
	{
		private var _fla:MovieClip;
		private var _miaroot:MovieClip;
	
		public function Chiama_Clip(fla:MovieClip,miaroot:MovieClip) 
		{
			_fla=fla;
			_miaroot=miaroot
			var mc1:Clip=new Clip();
			_miaroot.addChild(mc1);
			mc1.x=100;
			mc1.y=50;
			
			mc1.tavola.tabled.text="Scrivi Fatto";
			mc1.tavola.wait.gotoAndPlay(2);
		}
	}
}
it receives the values from Loadin.as so to be able to tell the loaded SWF to attach "clip_mc" placed in its library and associated (via linkage id) to the Clip.as class:
Code:
package
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	public dynamic class Clip extends MovieClip
	{
		
		public function Clip()
		{
			trace("La Classe Clip è Istanziata ")
		}
	}
}
Back to Chiama_Clip.as, we see that an instance of Clip.as is created and added to the loaded SWF (prova.swf)
var mc1:Clip=new Clip();
_miaroot.addChild(mc1);
it then refers to "mc1" to access and be able to interact with all the objects inside it.
Nothing special about it if not for the fact that we do know now how to attach a MovieClip placed in library of a loaded SWF.
But if we do take a closer look at the definition of Clip.as class
public dynamic class Clip extends MovieClip
We notice that there is the new word "dynamic".

As said first, the Clip class should already be dynamic by itself as it extends the MovieClip class and so should be able to create properties in runtime.
However, if we remove that word "dynamic" it does not happen that way.

I can say to have resolved completely this Flash error although I cannot understand the why of it.

I personally think that the Clip class loses its dynamic in the following line of the Chiama_Clip.as:
var sdsd=MovieClip(loader.content);
In which the content of "loader" is forced to be of type MovieClip (as if it would not be a 100% true property of MovieClip)
So, as Clip.as is associated to a MovieClip placed in library on the loaded SWF (placed itself in "loader"), Clip at that moment loses its dynamic side and we need to give it back to it via the class definition using the attribute "dynamic".

To understand best, you can download the complete files of this example in the downloads section on this site.

See you again soon!
__________________

 


I recommend: Essential Actionscript 3.0

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

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

  #2 (permalink)  
Old 03-10-07, 02:53
wes wes is offline
Junior Member
 
Join Date: Oct 2007
Posts: 2
Rep Power: 0
wes is on a distinguished road
If a class extends a dynamic class in AS 3.0 then the new class doesn't become dynamic too, so you have to make the new class dynamic explicitly that is why flash gives you error.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-10-07, 07:10
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
hmm, do you mean, if i extend MovieClip i do not inherit the dynamic ?
That's strange...
anyway thx for the tip
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-10-07, 13:03
wes wes is offline
Junior Member
 
Join Date: Oct 2007
Posts: 2
Rep Power: 0
wes is on a distinguished road
Quote:
Originally Posted by Flep View Post
hmm, do you mean, if i extend MovieClip i do not inherit the dynamic ?
Yes exactly. You might consult Colin Moock's Essential ActionScript 3.0 for dynamic programming.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-10-07, 14:07
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
Hi,
yes i do. I have that book.
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 13-01-08, 07:37
Junior Member
 
Join Date: Dec 2007
Posts: 12
Rep Power: 0
cooljackD is on a distinguished road
Re: How to refer to a MovieClip placed in library of a loaded SWF?

where can i download the files for this tutorial, its under wot name in the download section ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 13-01-08, 09:45
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
Re: How to refer to a MovieClip placed in library of a loaded SWF?

There are not.
Also, you should use Event.ADDED_TO_STAGE into Chiama_Clip class, so you do not need to pass any value.

Have a look:
Event.ADDED_TO_STAGE
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 24-10-08, 21:53
davidjmcclelland.com's Avatar
Junior Member
 
Join Date: Mar 2008
Location: Finger Lakes Area, NY, USA
Posts: 6
Rep Power: 0
davidjmcclelland.com is on a distinguished road
Send a message via Yahoo to davidjmcclelland.com
Re: How to refer to a MovieClip placed in library of a loaded SWF?

I think you are right about where Movieclip loses dynamic quality.

Have you tried this: var sdsd=MovieClip(loader.content) as MovieClip;

?
__________________
http://davidjmcclelland.com
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
Flash PHP Create Library book system for Flash PHP clonez Flash CS3 | PHP | mySQL 0 21-10-08 16:11
access loaded object jimbo Actionscript 3.0 newbies 6 18-10-07 13:20
tween display above loaded swf jimbo Actionscript 3.0 newbies 10 16-10-07 15:29
Attach image from library with Flash CS3 and Actionscript 3.0 Flep Tutorials 0 09-10-07 19:14
Library Sounds with Flash CS3 Flep Tutorials 0 25-09-07 16:36


All times are GMT. The time now is 19:01.

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