4 Replies Latest reply on Jul 3, 2008 1:33 PM by cyber fyb

    Reference to an object by String(ID)?

    cyber fyb Level 1
      I am trying to build a glow container/manager in order to turn off and turn on appropriate component. In fact, when a specific component respond to a click, it will be glowed. But if the user click on another specific component, the previous glowed should unglow and the new one will be glowed.

      Now, to do this, I created a class with 2 elements: objReference:String and glowActive:Boolean. I also created an ArrayCollection of all the component that can respond to the glow effect and put them inside like this:

      objReference = [object].ID

      And every component get FALSE for glowActive at the initiation of the ArrayCollection.

      I have a problem with the recognization of the object ID. When I tried to play the glow using the objReference, the system indicate the following error:

      TypeError: Error #1006: value is not a function.
      at mx.effects::EffectInstance/play()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\effec ts\EffectInstance.as:584]
      at mx.effects.effectClasses::GlowInstance/play()[E:\dev\3.0.x\frameworks\projects\framework\ src\mx\effects\effectClasses\GlowInstance.as:194]
      at mx.effects::EffectInstance/startEffect()[E:\dev\3.0.x\frameworks\projects\framework\src\m x\effects\EffectInstance.as:569]
      at mx.effects::Effect/play()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\effects\Effec t.as:930]
      at accueil/setCategoryGlowIn()[C:\Documents and Settings\DJ FYB\My Documents\CharlesValcourt\includes\charlesvalcourt_logique.as:303]
      at accueil/clickCategoryBox()[C:\Documents and Settings\DJ FYB\My Documents\CharlesValcourt\includes\charlesvalcourt_logique.as:282]

      I am a bit confuse on how to call an object by reference and stored the referene of the object in somewhere else (in my case, in a ArrayCollection).
        • 1. Reference to an object by String(ID)?
          cyber fyb Level 1
          Sorry I forgot to mention how to reproduce the error!!!

          Let's say that I defined the following lines of glow like this:

          <mx:Glow id="glowIn" duration="500"
          alphaFrom="1.0" alphaTo="0.3"
          blurXFrom="0.0" blurXTo="50.0"
          blurYFrom="0.0" blurYTo="50.0"
          color="0x00FF00"/>

          and

          <mx:Glow id="glowOut" duration="500"
          alphaFrom="0.3" alphaTo="1.0"
          blurXFrom="50.0" blurXTo="0.0"
          blurYFrom="50.0" blurYTo="0.0"
          color="0x0000FF"/>


          And if I want to glow a specific component while I loop over the ArrayCollection of the GlowContainer, I tried to do this without success:


          • 2. Re: Reference to an object by String(ID)?
            ntsiii Level 3
            First, this will not work:
            myHB.ID = "myHBID";
            Well, it assigns that string to the id property of the component, but you *cannot* use that id to reference the component. That only works when you declare an id property in an mxml tag.

            If you are dynamically creating instances, then you must maintian a list of actual references to the instances yourself.

            Why not pass the actual reference into your _objReference property?

            alternatives to ArrayCollection would inclyude an "associative aray" or "hashmap", which is implemented using the Object class. Use your ID as the key to the actual reference.

            You could also use Dictionary. I would use associative array myself.

            Tracy
            • 3. Re: Reference to an object by String(ID)?
              cyber fyb Level 1
              Hi Tracy, this is exactly what I want to do but I just missing the way to store the reference while I am creating the object dynamically (the HBox). I tried many different things but without any success.

              Base on your knowledge, what will be the type of the _objRerefence and what will be the code to transmit the HBox reference to that property?

              Let's say that we create a HBox and the _objReference is shorten here to the property in my class (I just want to make it simple here instead of putting too many code) :

              var myHB:HBox = new HBox();
              _objReference = myHB; ??? (this not work either)
              • 4. Re: Reference to an object by String(ID)?
                cyber fyb Level 1


                Youpi!!! I found how to made it!!!

                First, I finally have to make the property objReference in my class GlowObjectReferencer as an Object in order to work.

                Than, I have to pass myHB as the Object (which, if I understand properly, will put a reference of the current Object into the new class Object).

                var _objReference:GlowObjectReferencer = new GlowObjectReferencer (myHB, false);

                And when I run my functions to manage the Glow FX (setAllCategoryGlowOut and setCategoryGlowIn), it is now working fine!!!

                I am so happy now! I knew it was possible but in my mind, it was just not logic to store an Object in the class but it seems that it is what I need to do! But just to make sure: what I pass to the class GlowObjectReferencer as the first property is only the reference to myHB? Not a copy of myHB; right?

                Again, thank Tracy because you force me to find the way to do it!!! ;-))