A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: External SWF - Accessing Loader() of Main SWF

  1. #1
    Member
    Join Date
    Dec 2005
    Posts
    61

    External SWF - Accessing Loader() of Main SWF

    Hello,

    In my main swf I have a menu that loads external swf files into the main swf's content area. There is only one external swf loaded at a time. Each click on the menu, will overwrite the existing swf using the same Loader(). This is working as planned...

    The problem is...

    In the external swf I want to create a link that will load another external swf into the main swf's Loader(). Basically replacing itself with another swf.

    From the external swf, I can use trace(root.loaderInfo) successfully. How can I access my existing Loader() on the main swf from this external swf?

    Here is an example of how I'm using it.

    User clicks on "Games" button. This loads a games.swf into the content area of the main swf. Games.swf contains links to various games that can be created. When a link is clicked in games.swf it should load the appropriate setup.swf for that game. The setup.swf would overwrite the games.swf by using the same Loader() from the main swf.

    Thanks for any help,

    Regards,
    Brent

  2. #2
    Member
    Join Date
    May 2007
    Posts
    35
    From games.swf you can use

    root.loaderInfo.loader
    or
    Loader(root.parent)

  3. #3
    Member
    Join Date
    Dec 2005
    Posts
    61
    Thanks for the response. I couldn't get "root.loaderInfo.loader" to work. When I traced it returned the following error:

    Code:
    Error: Error #2099: The loading object is not sufficiently loaded to provide this information.
    	at flash.display::LoaderInfo/get loader()
    	at games_fla::MainTimeline/games_fla::frame1()
    Your second suggestion of "Loader(root.parent)" worked...

    Code:
    var request:URLRequest = new URLRequest("external/redmen_setup.swf");
    var ldrContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
    Loader(root.parent).load(request, ldrContext);
    Should the first one of worked?

    Thanks again...
    Brent

  4. #4
    Member
    Join Date
    May 2007
    Posts
    35
    Well it did work. Sort of. That error just means you were trying to access the loaderInfo.loader property before the loader was finished loading and you can't do that. You can however get information about the loader (specifically the loading process) from the loaderInfo.

    For example:

    root.loaderInfo.addEventListener(ProgressEvent.INI T, onInit);

    function onInit(event:ProgressEvent)
    {
    // place your code here
    // you can reference the loader now by LoaderInfo(event.target).loader
    }

  5. #5
    Member
    Join Date
    Dec 2005
    Posts
    61

    Thanks... one more issue

    Thanks for the follow-up.

    I'm having another issue with the external setup.swf. When this setup.swf is loaded it creates radio buttons using AS3. When I run setup.swf on its own the radio buttons work fine. When I load setup.swf into main.swf, I get the following error:

    Code:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at fl.controls::RadioButton/fl.controls:RadioButton::drawLayout()
    	at fl.controls::LabelButton/fl.controls:LabelButton::draw()
    	at fl.controls::RadioButton/fl.controls:RadioButton::draw()
    	at fl.core::UIComponent/::callLaterDispatcher()
    I receive this error per radio button (x3 right now)

    I can see the text for each radio button but not the actual radio button graphic (round image). I've tried to trace everything possible and it all returns correctly... I can not figure out what this error means. I do not have a draw or drawLayout so I'm assuming these are internal somehow.

    Any hint on what may be happening?

    Thanks,
    Brent
    Last edited by Battlespace; 07-25-2007 at 06:19 AM.

  6. #6
    Member
    Join Date
    Dec 2005
    Posts
    61

    fixed that one... but caused another

    Ok, I was able to eliminate the errors by making sure to pass the ldrContext as shown below:

    Code:
    var ldrContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
    Loader(root.parent).load(request, ldrContext);
    When I used: Loader(root.parent).load(request); without the ldrContext is when I would get the radio button error messages.

    The reason I removed it was because if clicked on setup.swf more than once, would not overwrite the existing one... I could see two instances of the setup.swf. It is really strange because I can load other swfs into the main swf and they are removed. Even the setup.swf disappears... but for some reason when the setup.swf is loaded again it is appearing for each click.

    Any hints as to how I can ensure the setup.swf is starting over each time it is loaded? I thought using the same loader would overwrite the existing swf. Is there some sort of cache?

    Thanks for your continued help,
    Brent

  7. #7
    Member
    Join Date
    May 2007
    Posts
    35
    I receive this error per radio button (x3 right now)
    Are you trying to access the shell before the buttons have been added to the stage (for example in the constuctor).



    I've never used LoaderContext, can't really help you there. I guess the only thing I can think of is that you're calling myLoader = new Loader() on every click. Even though the variable it is stored to is the same it now points to a new memory location where a new Loader resides. But the old loader is still around in memory but with no references to it (unless you have event listeners, but anyway) and will only disappear once it has been garbage collected.

    So to avoid this only call new Loader() in your init, and from then only use the load method.

    This may not be your problem though :/

  8. #8
    Member
    Join Date
    Dec 2005
    Posts
    61
    Quote Originally Posted by Martin Munoz
    I guess the only thing I can think of is that you're calling myLoader = new Loader() on every click.
    No, only during init... I'll work on it some more. Thanks for your help.

    Regards,
    Brent

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