4 Replies Latest reply on Feb 8, 2010 5:38 PM by Ben-BLTek

    Embedding symbols inside symbols that are runtime exported.

    Ben-BLTek

      I'm attempting to use CS4 (PC/Vista, if that matters) to create a SWF file that will basically act as a "library" of commonly used symbols. This SWF would be loaded at runtime by other SWFs, which could then use the symbols within it, including all art and code assets.

       

      To accomplish this, I'm following the directions here: http://help.adobe.com/en_US/Flash/10.0_UsingFlash/WSd60f23110762d6b883b18f10cb1fe1af6-7dc9 a.html#WSd60f23110762d6b883b18f10cb1fe1af6-7dc6a

       

      However, I'm having a strange issue...

       

      My "Clock" symbol (it's a class defined in an external .as file, which extends MovieClip) has an internal "SecondHand" (also a symbol, but just a plain old MovieClip, no external .as file). I have exported both these symbols for runtime sharing as explained on the above page. And put the resulting SWF up on the web, so other SWFs can download it. (This is what I'm considering the "library" SWF.)

       

      Then in my second SWF, I follow the directions as explained under "Link a shared asset to a destination document by entering the identifier and URL". In other words, I make a new symbol, right-click it and select "Properties", check "import for runtime sharing", type in the correct URL of the "library" SWF, and type in the correct Class name of my "clock" symbol from the library SWF. And also make sure the name of the symbol matches the name of the symbol in the "library" SWF.

       

      I run the second SWF, and it does manage to load up the "library" SWF (I can verify this happens in the webserver logs), and the clock appears on the screen - complete with a second hand. However, I then get an error like this:

       

      "Clock.as, Line 29: Access of undefined property secondHand."

       

      Clock.as:29 is:

       

      secondHand.rotation = (secs % 60) * 6;

       

      It's worth noting here that "secondHand" is an instance of the symbol "SecondHand". This instance was created when I made the "library" SWF in CS4. I double-clicked the "Clock" symbol in the library pane to edit it. Then I dragged a copy of the symbol "SecondHand" into that Clock. Then I used the "Properties" tab to make the name of that instance "secondHand". In other words, I probably did it exactly way you'd expect someone to do this. Nothing fancy or weird, as far as I can tell.

       

      So... there's something very strange going on here. Somehow, my "secondHand" isn't being created when the "Clock" symbol is instantiated. My assumption was that since I dragged and dropped the symbol while I was editing the "Clock" MC, the code to create the "secondHand" instance would get attached to frame1 of the "Clock" symbol. But evidently not...

       

      The thing that really hurts my brain, though is this: if the "secondHand" instance is never being created.... how come the second hand shows up on-screen? I mean sure, there could be some "cache as bitmap" stuff going on behind the scenes, but even so that just seems weird. The loading SWF obviously isn't creating the secondHand object. And yet you can see said object right there on-screen!

       

      I've tried many searches for many variations of "flash runtime import symbol loading", but found nothing relevant. The above linked doc page just blithely assumes that everything will magically work out - as most of the Adobe docs so cutely do.

       

      So, questions...

       

       

      A) Am I doing something obviously wrong?

       

      B) Has anyone else seen this before? (Known bug?)

       

      C) Does anyone know of a workaround?

       

       

      If anyone wants .FLAs/SWFs demonstrating the problem, I'm happy to provide. Just ask.

       

      It's the weekend, but I'll try and check back on this topic once or twice a day just in case anyone answers.

        • 1. Re: Embedding symbols inside symbols that are runtime exported.
          Ben-BLTek Level 1

          Just giving this a quick bump since it's Monday. If nobody here has any input, I'll go bug the ActionScript forums next.

           

          An update on the problem: I tried unchecking "Export in frame 1" on the symbols, on the theory that having it checked might make the Symbol instantiation code appear on the main timeline, instead of within my "Clock" symbol's timeline. Sadly, this didn't make any difference. I'm still seeing the exact same error, the exact same way.

          • 2. Re: Embedding symbols inside symbols that are runtime exported.
            Ned Murphy Adobe Community Professional & MVP

            I'll be honest, last week I got about a 25% thru your writeup and lost interest... chances are others had the same sentiment kick in.  If you do post again, try to shorten things up.  Don't expect folks to go looking thru external tutorials to see what you might be doing.  While it might be tough, try to be to the point explaining what you're doing, what isn't working, and what code might be involved that could contribute to the issue.

            • 3. Re: Embedding symbols inside symbols that are runtime exported.
              Ben-BLTek Level 1

              Yeah, it's a pretty obnoxious post. I wish I could supply a TL;DR for it, but I'm having trouble coming up with a quick summary of the problem. It's one of those things that only happens when you do X, then Y, then Z in a certain way. And I felt like if I didn't give all the steps in exact detail, I'd get bad answers. I also figured it was better to give too much information, rather than too little.

               

              Never the less, I appreciate your advice. I'll try and do whatever I can to cut it down as far as I think I can get away with, before I post in the AS forum. Thanks.

              • 4. Re: Embedding symbols inside symbols that are runtime exported.
                Ben-BLTek Level 1

                After a long, frustrating day of trying every possible thing I could think of, there doesn't seem to be a way to make this work correctly at compile time. I finally settled on doing an end-run around CS4 at run time.

                 

                in Clock.as:

                 

                var secondHand:MovieClip = this.getChildByName("secondHand");

                 

                This uses DisplayObjectContainer's getChildByName() function to walk the display list and find the object with the given name.

                 

                It's possible you may need to delay doing this until *after* the Clock has been added to the stage. If that's how you have to use it, then put a handler on the Event.ADDED_TO_STAGE event and don't do the above code until you're sure the object has been added to the stage.