3 Replies Latest reply on May 5, 2009 11:32 PM by stephan.k

    Flash library items export as .swc files for Flex

    stephan.k Level 1

      Hello Forum

       

      I'm trying to wrap my head around this problem but I can't really figure it out.  I have a feeling I'm approaching it the wrong way.  Maybe someone can help me...?

       

      I'm using Flash CS4 to create a timeline with 4 strips.  Each strip has the same movieClip instances [headerBg, headerTxt, bodyBg], but with slight variations (different color, width, height...).  

       

      I export the four strips from the library with the class names: Strip0, Strip1, Strip2, Strip3, each using Sprite as the base class.

       

      Then I export the project as a .swc file and link to it from Flex Builder3.

       

      To instantiate the four items in Flex Builder I use the following code:

       

      ---------------------------------------------------------------------------------

                  tlStrip0 = new Strip0();
                  tlStrip1 = new Strip1();
                  tlStrip2 = new Strip2();
                  tlStrip3 = new Strip3();
                 
                  strips = new Sprite();
                  strips.addChild(tlStrip0);
                  strips.addChild(tlStrip1);
                  strips.addChild(tlStrip2);
                  strips.addChild(tlStrip3);
                 
                  tlStrip0.bodyBg.alpha = 0;
                  tlStrip1.bodyBg.alpha = 0;
                  tlStrip2.bodyBg.alpha = 0;
                  tlStrip3.bodyBg.alpha = 0;
                 
                  InstanceManager.STAGE.addChild(strips);

      ---------------------------------------------------------------------------------

       

      This works.  Now my Question:  Since the four strips have essentially the same functionality and basic structure, how can I simplify this code?  The problem being that the Strip MovieClip is manually created in Flash (by the designer),  How can I create a baseclass which automatically sets the bodyBg.alpha to zero?

       

      Any insight is much appreciated!

       

      Cheers,

       

      sk

        • 1. Re: Flash library items export as .swc files for Flex
          stephan.k Level 1

          as I continue writing the code I realize that I have to find a way to create a parent class (or is it called a super class?)  anyway...  the redundancy becomes more and more apparent...   Any help out there???  I'm about to pull my hair out...

           

          -------------------------------------------------------------------------------- -

                      tlStrip0 = new Strip0();
                      tlStrip1 = new Strip1();
                      tlStrip2 = new Strip2();
                      tlStrip3 = new Strip3();
                     
                      strips = new Sprite();
                      strips.addChild(tlStrip0);
                      strips.addChild(tlStrip1);
                      strips.addChild(tlStrip2);
                      strips.addChild(tlStrip3);
                     
                      tlStrip0.bodyBg.alpha = 0;
                      tlStrip1.bodyBg.alpha = 0;
                      tlStrip2.bodyBg.alpha = 0;
                      tlStrip3.bodyBg.alpha = 0;
                     
                      InstanceManager.STAGE.addChild(strips);

                
                      tlStrip0.x = model.getTimelineMCHome().s0.x;
                      tlStrip1.x = model.getTimelineMCHome().s1.x;
                      tlStrip2.x = model.getTimelineMCHome().s2.x;
                      tlStrip3.x = model.getTimelineMCHome().s3.x;
                     
                      tlStrip0.y = model.getTimelineMCHome().s0.y;
                      tlStrip1.y = model.getTimelineMCHome().s1.y;
                      tlStrip2.y = model.getTimelineMCHome().s2.y;
                      tlStrip3.y = model.getTimelineMCHome().s3.y;

           

          --------------------------------------------------------------------------------

           

          Thanks for your time...

           

          Best,

           

          Stephan

          • 2. Re: Flash library items export as .swc files for Flex
            stephan.k Level 1

            Following this thread (http://www.actionscript.org/forums/showthread.php3?p=86039)   tried to use the same baseclass (TimelineStrip.as) for all 4 timeline strips in the flash IDE and then manually with a setup function initialize the necessary parameters.  I like this structure better however the movieClip instances inside Strip0 /1 /2 / 3 can again not be read by Flex.  The tlStrip0.bodyBg instances are passed without throwing errors however the alpha doesn't change...

             

            any ideas?

             


            -----------------------------------------------------
            Main Class
            -----------------------------------------------------
            [...]

             

            tlStrip0 = new Strip0();
            tlStrip1 = new Strip1();
            tlStrip2 = new Strip2();
            tlStrip3 = new Strip3();
                   
            tlStrip0.setup(0,model.getTimelineMCHome().s0,model.getTimelineMCNeutral().s0,tlStrip0.bod yBg,tlStrip0.headerBg);
            tlStrip1.setup(1,model.getTimelineMCHome().s1,model.getTimelineMCNeutral().s1,tlStrip0.bod yBg,tlStrip1.headerBg);
            tlStrip2.setup(2,model.getTimelineMCHome().s2,model.getTimelineMCNeutral().s2,tlStrip0.bod yBg,tlStrip2.headerBg);
            tlStrip3.setup(3,model.getTimelineMCHome().s3,model.getTimelineMCNeutral().s3,tlStrip0.bod yBg,tlStrip3.headerBg);

             

            strips = new Sprite();
                   
            strips.addChild(tlStrip0);
            strips.addChild(tlStrip1);
            strips.addChild(tlStrip2);
            strips.addChild(tlStrip3);

             

            InstanceManager.STAGE.addChild(strips);
            [...]
            -----------------------------------------------------

             


            -----------------------------------------------------
            TimelineStrip.as
            (Baseclass for Strip0, Strip1, Strip2, Strip3 in Flash Library)
            -----------------------------------------------------

             

            public class TimelineStrip extends MovieClip
            {
                   
                //id
                private var id:int = 0;
               
                //references
                private var refHome:Sprite;
                private var refNeutral:Sprite;
                   
                //layout
                private var bodyBgMC:Sprite;
                private var headerBgMC:Sprite;
                   
                   
                public function TimelineStrip():void
                {
                }
                   
                public function setup(_id:int,_refHome:Sprite,_refNeutral:Sprite,_bodyBg:Sprite,_headerBg:Sprite):void
                {
                    this.id = _id;
                    this.refHome = _refHome;
                    this.refNeutral = _refNeutral;
                    this.bodyBgMC = _bodyBg;
                    this.headerBgMC = _headerBg;
                   
                    this.x = refHome.x;
                    this.y = refHome.y;
                   
                    this.bodyBgMC.alpha = 0.3;     // >> This doesn't work, bodyBg and headerBg are instances in the Strip0/1/2/3  classes created in flash)
                    this.headerBgMC.alpha = 0.3;   // >> This doesn't work, bodyBg and headerBg are instances in the Strip0/1/2/3  classes created in flash)
                }       
            }

            • 3. Re: Flash library items export as .swc files for Flex
              stephan.k Level 1

              after a little bit of debugging I notice the following:

               

              If I use flash.display.MovieClip as the base class for Strip0, flex recognizes all MovieClips contained by Strip0 (bodyBg, headerBg...).  If I use TimelineStrip.as as the baseclass for Strip0, Flex doesn't recognize the MovieClips... or it seems like it can read their properties but not setting them... (not sure about this though).

               

              This is really confusing

               

              any help out there?

               

              Thank you

               

              sk