7 Replies Latest reply on May 13, 2009 8:16 AM by Ned Murphy

    Dynamic InstanceName

    THE SU66LER

      I have a flash map that contains 51 movieClips, one for each state.

      Sample instanceName for a state (Alabama) would be:

      S_01

       

      I have a XML record that contains specific info for each state.

      <stateID>01</stateID

       

      I am trying to link the stateID's in the XML record to the state movieClips that make up the map.

       

      var stateInstanceName = 'S_' + stateID;

       

      I was just trying to do a simple trace command to see if I could pull the _width of each state clip to see if I was linked up:

       

      trace(mapInstance.stateInstanceName._width)

       

      This is not working from me. I'm not even sure its the right way to go about it.

      Any guideance would be great!

       

      Thanks

        • 1. Re: Dynamic InstanceName
          Ned Murphy Adobe Community Professional & MVP

          Try:

           

          trace(mapInstance[stateInstanceName]._width);

           

          the value is merely a string, so you need to use the array notation to have it interpretted as an object.

          • 2. Re: Dynamic InstanceName
            grover970

            Spoke to soon.

             

            So, this worked...

            trace('content_mc.nAmerica[stateInstance]._width);

            But if I try to tween it:

            var mcTween:Tween = new Tween( content_mc.nAmerica[stateInstance], "_alpha", Strong.easeOut, 0, 100, 2, true );

             

            or say I want to change the color of certain states:

            changeColor = new Color(content_mc.nAmerica[stateInstance]);
            changeColor.setRGB(0x00FF66);

             

             

            nothing happens.

            • 3. Re: Dynamic InstanceName
              Ned Murphy Adobe Community Professional & MVP

              It may be a problem with mis-naming something somewhere along the line.  If I take the code you just provided and recreate a scenario with it, with S_01 buried within mc's per what your code implies, it works fine...

               

              import mx.transitions.Tween;
              import mx.transitions.easing.Strong;

               

              var stateInstance = "S_01";

               

              trace(content_mc.nAmerica[stateInstance]._width);

               

              var mcTween:Tween = new Tween( content_mc.nAmerica[stateInstance], "_alpha", Strong.easeOut, 0, 100, 2, true );


              var changeColor = new Color(content_mc.nAmerica[stateInstance]);
              changeColor.setRGB(0x00FF66);

              • 4. Re: Dynamic InstanceName
                grover970 Level 1

                Yeah this is weird. I am using that exact code. I also created a similar scenario in a seperate file where everything worked fine.

                 

                 

                The trace code works just fine. But when I try to tween it or setRGB it seems to ignore it. I think I'll just have to come back to it tomorrow and look at it with fresh eyes.

                • 5. Re: Dynamic InstanceName
                  Ned Murphy Adobe Community Professional & MVP

                  If it's not a naming issue, it might be a location issue--the code needs to be in the presence of the object it's trying to control.

                   

                  One other oddity that sometimes comes into play... if things are timeline tweened into the place where the code is, and the initial keyframe doesn't have an instance name, or isn't the same name, the object at the end of the tween inherits that same name, even if you have it entered in the properties panel.

                  • 6. Re: Dynamic InstanceName
                    grover970 Level 1

                    Thanks Ned,

                     

                    I came back to it with fresh eyes and a new persepective this morning and found the issue. It was infact a naming issue. If I had just looked at a line of code about 10 lines earlier I would have seen this line:

                     

                    var maps = content_mc.nAmerica.duplicateMovieClip("tabItem" + i, i, verticalData);

                     

                    therefore this:

                    content_mc.nAmerica[stateInstance]

                     

                    should have been this:

                    maps[stateInstance]

                     

                    Thanks for your help

                    Ben

                    • 7. Re: Dynamic InstanceName
                      Ned Murphy Adobe Community Professional & MVP

                      You're welcome