1 Reply Latest reply on Jun 3, 2007 4:09 PM by peterent

    SWFLoader - Dynamic

      Using the SWFLoader Documentation and specifically this line:


      public function updateNestedVarOne():void {
      local(loadedSM.application).setVarOne("Updated varOne!");

      Where is it getting the function "local" from? I see no reference to this in the docs. I've copied the example files EXACTLY and I get an error on this constructor... can anyone supply more information?

      Here's a problem, it does not work if I follow these steps:
      1) Create a project called local
      2) Copy the local.mxml example code
      3) Build local into a swf
      4) Create a project called localloader
      5) Copy the local.swf to localloader
      6) Copy the second block of example code
      7) Immediately get an error "call to a possibly undefined method local"

      However it does work if I do this:
      1) Create a project called localincluded
      2) Create a component in that project called local
      3) Copy the local.mxml example code
      4) Copy the second block of example code
      5) Run the project

      What gives?

      This is all I want to do, and I've spent most of the last two days looking for an answer: I have an external SWF that has a bunch of stuff in its library. I can get it out like this:
      [Embed(source='Library.swf', symbol='Header_1')]
      public var Header_1:Class;

      This works fine but it is not dynamic. This needs to be dynamic. I need to be able to call that swf at runtime, not compiled into the application. I need to do that, right there dynamically...
        • 1. Re: SWFLoader - Dynamic
          peterent Level 2
          When I read that documentation I think it means to use a single Flex application project with 2 main swfs, one of which is called local.mxml. When you create a component MXML file, even if its root tag is Application, you have created a class by that name as if you had written it in ActionScript. Thefore, local.mxml defines the class, local.

          In the other main application swf, you can use local() because it is in the same package and the compiler is simply picking it up from the class path which includes "." (current) directory.

          If you use separate projects, then you need to place the definition for the local class either in your other project, which effectively defeats the purpose of having 2 separate projects, or add the local app's project's path to the class path of the second project.

          What the example doesn't show is a better of doing this using interfaces. This allows you to keep the applications completely separate, sharing only the interface definition between them. It also doesn't cause linking problems with getting the local class compiled into the second project.

          Read up on ActionScript interfaces, it makes separating the two SWFs easier and cleaner. You can also read about this technique in the documentation for Modules.