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 8 of 8

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

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

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

    amazing Flash templates
    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!

  2. #2
    Junior Member Settled In wes is on a distinguished road
    Join Date
    Oct 2007
    Posts
    2
    Rep Power
    0
    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.

  3. #3
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,454
    Rep Power
    8
    hmm, do you mean, if i extend MovieClip i do not inherit the dynamic ?
    That's strange...
    anyway thx for the tip

  4. #4
    Junior Member Settled In wes is on a distinguished road
    Join Date
    Oct 2007
    Posts
    2
    Rep Power
    0
    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.

  5. #5

  6. #6
    Junior Member Settled In cooljackD is on a distinguished road
    Join Date
    Dec 2007
    Posts
    12
    Rep Power
    0

    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 ?

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

    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

  8. #8
    Junior Member Settled In davidjmcclelland.com is on a distinguished road davidjmcclelland.com's Avatar
    Join Date
    Mar 2008
    Posts
    11
    Rep Power
    0

    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

+ Reply to Thread

Similar Threads

  1. Replies: 1
    Last Post: 26-01-10, 13:23
  2. Replies: 1
    Last Post: 27-10-08, 15:24
  3. Create Library book system for Flash PHP
    By clonez in forum Flash CS3 | PHP | mySQL
    Replies: 0
    Last Post: 21-10-08, 16:11
  4. tween display above loaded swf
    By jimbo in forum Actionscript 3.0 newbies
    Replies: 10
    Last Post: 16-10-07, 15:29
  5. Library Sounds with Flash CS3
    By Flep in forum Tutorials
    Replies: 0
    Last Post: 25-09-07, 16:36

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