A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: How to load to a container in this new fangled Flash world?

  1. #1
    the friendly canadian DaVulf's Avatar
    Join Date
    Feb 2004
    Location
    Singapore
    Posts
    2,017

    How to load to a container in this new fangled Flash world?

    Hey all,

    I haven't used Flash since before AS2.0 became all of the rage, and so it seems that some of my coding is a little outdated.

    I've noticed that I'm having trouble with:

    Code:
    _root
    _parent
    I'm having trouble assigning MC.onMouseOver style events to my movie clips. It is all very complicated.

    In any event, the question I have is pertaining to loading a SWF file to a container. It used to be pretty easy to do, but clearly I've either forgotten due to disuse, or it has changed.

    My code:
    Code:
    function upstreamClick(event:MouseEvent):void
    {
                 ZMC_CONTAINER.unload();
    	this.gotoAndPlay(2);
    	ZMC_CONTAINER.load(test1.swf);
    }
    ZMC_LOB_MAIN.ZMC_UPSTREAM.addEventListener(MouseEvent.CLICK, upstreamClick);
    On my stage I have a MC called ZMC_CONTAINER. Thanks for the help!

  2. #2
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    Hi there.

    First of all: _root and _parent were changed into: root and parent without the underscores. Btw, using "root" is not a good practice so it would be really great if you try avoiding root.

    Regarding your problem: well, AS changed a lot since AS 1.0 and AS 2.0... AS 3.0 is a totally new language and almost nothing works the same way in AS 3.0 as it did in the previous versions. To load an external .swf file you need to use the Loader class and your code would look something like this:

    PHP Code:
    ZMC_LOB_MAIN.ZMC_UPSTREAM.addEventListener(MouseEvent.CLICKupstreamClick);

    function 
    upstreamClick(event:MouseEvent):void
    {
       
    gotoAndPlay(2);

       var 
    loader:Loader = new Loader();
       
    loader.load(new URLRequest("test1.swf"));
       
    loader.addEventListener(Event.COMPLETEloadComplete);
    }

    function 
    loadComplete(event:Event):void
    {
        
    // add the loaded .swf into the ZMC_CONTAINER
        
    ZMC_CONTAINER.addChild(event.target.content);

    As for unload(); well, things changed there too... if you want then you can unload(); the content of your loader object by loader.unload(); but for that to happen, you'll have to define the loader variable globally and not locally as I did ( meaning that you have to define it outside the function ).

    IMHO, just hit F1 in Flash CS3 and read up on the Loader class because you'll understand it much better. It's nothing hard just that it's different from what you've been used to in AS 2.0 or AS 1.0

    Good luck.



    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


  3. #3
    the friendly canadian DaVulf's Avatar
    Join Date
    Feb 2004
    Location
    Singapore
    Posts
    2,017
    Hmm....

    Thanks for the snippet of code. I tried that out, but for some reason it isn't loading. If I change the path to an absolute path (g:\Flash Files\test1.swf) then it says the URL cannot be found.

    I'm a little unsure as to why. As a relative path, it should find the swf in the same directory, no?

  4. #4
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    Ahh... Sorry, it was my bad, I accidentally forgot to add something to the code. The event listener should have looked like this: loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, loadComplete);

    I've put together a fast example, download it and test it.
    Attached Files Attached Files



    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center