8 Replies Latest reply on Nov 16, 2010 12:27 PM by cayennecode

    Symbols + Base-Class Workflow

    cayennecode Level 1

      I frequently create a lot of Library Symbols, export for Actionscript, letting Flash auto-generate the Class & extending a custom base-class in order to give them all custom functionality w/out having to create a Class for each, and/or without having to create a FactoryClass for instantiating X number of ClassObjects for each Symbol to be added to.

       

      It's really fast for prototyping, and with this workflow I've only hit a few obstacles.  Those are:

       

      1 - If the Symbol has children you cannot give the children instance-names, else the compiler gives an error related to automatically declaring stage instances.  Two workarounds for this are that you can uncheck automatically declare stage instances, and do it manually in your base-class.  or you can avoid using instance-names, and use getChildAt().

       

      2 - If the Symbol is a MovieClip, the timeline doesn't inherit the base-classes imports.  I don't have a workaround for this.

       

       

      My question is, are these limitations that could be addressed by Adobe's Flash team, or are they limitations that are unavoidable without altering the workflow?

        • 1. Re: Symbols + Base-Class Workflow
          kglad Adobe Community Professional & MVP

          1.  i don't see any problem when assigning an instance name to a child movieclip.  what do you see?

           

          2.  i don't understand that statement.

          • 2. Re: Symbols + Base-Class Workflow
            cayennecode Level 1

            1-  If you have several MovieClip symbols exported for Actionscript, using auto-generated Classes, extending the same base-class, and they share children with the same instance name, Flash generates an error like this one:

             

            Warning: All instances named 'head' will be automatically declared as JessHead in symbols that use Character as their base class. In symbols that are linked to user-defined base classes, instances with the same name must be of the same type.

            And then the runtime error:
            TypeError: Error #1034: Type Coercion failed: cannot convert EmilyHead@3a0d1e81 to JessHead.
            at flash.display::Sprite/constructChildren()
            at flash.display::Sprite()
            at Character()
            2 MovieClips extending a base-class don't have Object level access to the classes which the base-class import.  It makes sense on a technical level, but is a definite obstacle if your timeline uses code, and you don't want to import the code on the timeline itself ( which becomes redundant & more difficult to manage with over a dozen Symbols ).
            • 3. Re: Symbols + Base-Class Workflow
              kglad Adobe Community Professional & MVP

              why do you have children with the same name and not the same data type?

              • 4. Re: Symbols + Base-Class Workflow
                cayennecode Level 1

                Because the child Symbols extend a base-class, and the Class must be unique in Flash.  I suppose I should add that condition to the 1st limitation, and note that it's only an issue when using more than one Symbol in this manner.

                 

                If the Symbols have children which also extend a base-class, you cannot give the children instance-names, else the compiler gives an error related to automatically declaring stage instances.

                 

                "Please enter a unique class name that is not associated with other library symbols."

                • 5. Re: Symbols + Base-Class Workflow
                  kglad Adobe Community Professional & MVP

                  cast the children as base class objects.

                  • 6. Re: Symbols + Base-Class Workflow
                    cayennecode Level 1

                    How?  This is all being done "behind the scenes" by the IDE.  Flash auto-generates a class for both objects, which extends the base-class.  It also auto-declares stage instances.

                    • 7. Re: Symbols + Base-Class Workflow
                      cayennecode Level 1

                      The only reasonable solution I can see is Adobe creating a resolution for this so that instances of the same name must only be of the same super type.  So the instance named "head" is declared as it's super class "Head" instead of it's auto-generated class "JessicaHead".

                       

                      Warning: All instances named 'head' will be automatically declared as JessicaHead in symbols that use Character as their base class. In symbols that are linked to user-defined base classes, instances with the same name must be of the same type.

                      • 8. Re: Symbols + Base-Class Workflow
                        cayennecode Level 1

                        Vote for this idea at ideas.adobe.com Flash Professional: http://tinyurl.com/2bxew2x

                         

                        Problem Description:
                        Using the Library to export Symbols for Actionscript hits a severe wall when Symbols use auto-generated classes + base-classes.  Child instances are declared as their auto-generated class type instead of their base-class.  The result is that you cannot create 2 Library Symbols with auto-generated classes which inherit from a user-defined base-class which have named child instances with auto-generated classes & a user-defined base-class.

                         

                        Steps to Reproduce:
                        1.     Create 2 Library Symbols, export for Actionscript with base-class "Character" which extends Sprite. Let Flash auto-generate Class names "Character1" & "Character2".

                         

                        2.     Create 2 more Library Symbols, export for Actionscript with base-class "Head" which extends Sprite. Let Flash auto-generate Class names "Character1Head" & "Character2Head".

                         

                        3.     Place an instance of Character1 on the stage, and give it a child instance of "Character1Head" named "head".

                         

                        4.     Place an instance of Character2 on the stage, and give it a child instance of "Character2Head" named "head".

                         

                        5.     Test Movie or Publish


                        Actual Result:
                        Warning: All instances named 'head' will be automatically declared as "Character1Head" in symbols that use "Character" as their base class. In symbols that are linked to user-defined base classes, instances with the same name must be of the same type.

                         

                        Expected Result:
                        Flash should declare all instances named "head" as their base-class type "Head" when using auto-generated Classes.  Save this workflow!!!