1 Reply Latest reply on Jun 8, 2007 11:21 PM by RoboticFX

    Setting an object property globally that belongs to another object.

    RoboticFX Level 1
      Hi,
      In flex builder I've layed out a Viewstack that I manipulate using a button bar. Inside the viewstack is an accordian navigator that has a canvas for each of its viewstates. Inside each canvas I have LinkButtons that when clicked perform my various actions.
      So it looks like this:
      Viewstack -> VBox - > Panel -> VBox - > Accordian -> Canvas - > LinkButton etc... repeated
      what I want to do is pass the LinkButton ID to a function when it's clicked so that I can change some of it's attributes. So for example:
      <mx:LinkButton id="LB_change_banner_text" x="10" y="10" label="Change Banner Text"
      click="myFunctionToChangeSomeAttributes();"/>


      An example function would be to change the link color:

      <mx:Style>
      .redText
      {
      color:#ff0000;
      }
      </mx:Style>
      <mx:Script>
      <![CDATA[
      public function myFunctionToChangeSomeAttributes():void
      {
      LB_change_banner_text.styleName="redText";
      }
      ]]>
      </mx:Script>

      The obvious problem is that it's not dynamic, so that I can send any object and manipulate its properties....
      I do not know how to send/recieve objects in actionscript 3, so my question is how to rewrite the function so that it is receiving a dynamic object that references an original. My assumption is to use pointers, but I'm not sure of the syntax.
      Any help is greatly appreciated.
      RFX
        • 1. Re: Setting an object property globally that belongs to another object.
          RoboticFX Level 1
          Hi again,
          I did a little fooling around and I got it to work. Here's what I did in case this helps someone else. If there's a better, more efficient way to do this, I'd love to hear from a guru, as I'm a novice flex/AS coder.
          The AS code:
          public var previousMenu:Object = null;
          public function ToggleMenuColor(cO:Object):void
          {
          if (previousMenu != null) previousMenu.styleName="blackText";
          previousMenu = cO;
          cO.styleName="redText";
          }
          mxml:
          <mx:LinkButton id="LB_change_banner_text" x="10" y="10" label="Change Banner Text" click="ToggleMenuColor(event.target);"/>

          It apears to work as expected. Hope this helps someone with a similar question.
          RXF