1 Reply Latest reply on Jul 13, 2008 2:53 PM by ntsiii

    Name variable with the string of an variable

    chaigneau
      hello,

      Can someone help me to resolve this problem

      <mx:Script>
      [Bindable]
      public var ref:String = "AZ48";

      [Bindable]
      public var piece:String = "door";

      [Bindable]
      public var [AZ48] = piece // an something like that ?
      </mx:Script>

      <!-- in order to display the variable cooling by his ref -->
      <mx:Text text="{AZ48}" /> <!-- Display : door -->



      Merçi
        • 1. Re: Name variable with the string of an variable
          ntsiii Level 3
          If the variable is already declared, you can use bracket notation to get a reference to it:
          [Bindable]
          public var piece:String = "";

          [Bindable]
          public var ref:String;

          private function myFunc():void
          ref = "piece";
          this[ref] = "door";

          should display "door in your binding.

          You can not "create" a var using bracket notation because Application is not dynamic. If you need this, create an Object, and add a reference to that.
          var oMyObj:Object = new Object();
          oMyObj[ref] = "door";

          Tracy