A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Accessing components in a loaded .swf

  1. #1
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136

    Accessing components in a loaded .swf

    Hi all...
    does anyone know how to access and especially, how to extend fl.controls. (components) stored in the library of a loaded .swf, from within that loaded .swf?
    Because basically, calls to new DataGrid() or extends DataGrid() from the loaded .swf only recognize and / or use components that are in the loading .swf's library. Meaning all components need to be in my preloader, which is obviously not desirable, and worse, something about the nature of doing it this way causes null reference errors to be thrown from somewhere in BaseScrollPane when I try to extend DataGrid...

    It's weird because, if the loading and the loaded .swf both contain a library element called Hello, and you call new Hello() from the loaded .swf, it looks only within itself to retrieve that class. But if you call new DataGrid() it seems only able to look within the library of the clip that loaded it. What's going on here?

    Thanks,
    Josh

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Hey Josh, long time no see.

    I'm afraid I don't follow your problem entirely, but this sounds like an ApplicationDomain issue. Are you specifying a particular domain when loading the swf?

  3. #3
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    Hey man. Thanks for responding. This is driving me crazy.

    I'm not specifying an applicationDomain when loading the .swf. Basically my HTML embed points to something called Initialize.swf, which just runs a loader, monitors progress, and loads something called Core.swf, containing all the code and library items for the program. When the loader finishes loading Core, I say:

    loader.contentLoaderInfo.content["init"]();

    init() being a public function in Core.as.

    At that point, Core grabs all the environmental vars it likes from its parent.parent (Initialize.swf) and the rest of the program executes. Core.swf contains all the fonts and all the code. And it's no problem creating an instance of a font, for example, that's in the Core library, from a class that's been created and added by Core and is in Core's applicationDomain (if in fact that's a different domain from Initialize, which I'm not certain it is). MovieClips, etc. all load out of the Core library the way they should, and classes don't go running up to Initialize looking to see if those MC's are in the library up there. They stay looking at Core's library and they behave. But if I say new DataGrid(), it always loads the DataGrid out of Initialize, completely ignoring the DataGrid component in Core. If the component doesn't exist in Initialize, it throws an error. Counter-intuitive...but what am I missing? I don't want to have to preload all the components...
    Last edited by joshstrike; 05-01-2008 at 04:16 AM.

  4. #4
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    Wow. Yeah. You were spot on.

    SOLVED. I set the applicationDomain to the currentDomain in the context of loading the .swf and...presto. Damn thing merged the libraries, it seems, and now the loaded .swf has access to its own components.

    Funny, because my assumption was that it would automatically be in the same domain...and anyway, that it would have searched its own domain first for a component. But hey. It works, and my loader .swf is now only 4k, and all those annoying componentShim errors have disappeared =)

    Thanks,

    Josh

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