Professional Web Applications Themes

Evaluating a variable that contains a variable - Macromedia Flex General Discussion

Hello, all: I have a bindable variable that contains the name of another variable that I want to return. Example: [Bindable] var price:String = "dollars"; [Bindable] var dollars: Number = "10.00" If I use {price} in some expression, the output is 'dollars'. I am looking for a way to use {price} and have it output '10.00'. How would I do this in AS 3? This would be like the ColdFusion function 'Evaluate()', where #Evaluate(price)#, which would return '10.00'. Any ideas would be highly appreciated. Thanks, Carlos...

  1. #1

    Default Evaluating a variable that contains a variable

    Hello, all:

    I have a bindable variable that contains the name of another variable that I
    want to return. Example:

    [Bindable]
    var price:String = "dollars";
    [Bindable]
    var dollars: Number = "10.00"

    If I use {price} in some expression, the output is 'dollars'. I am looking for
    a way to use {price} and have it output '10.00'. How would I do this in AS 3?

    This would be like the ColdFusion function 'Evaluate()', where
    #Evaluate(price)#, which would return '10.00'.

    Any ideas would be highly appreciated. Thanks,

    Carlos


    cheftimo Guest

  2. #2

    Default Re: Evaluating a variable that contains a variable

    I thought this might work, but it does not:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
    <![CDATA[
    [Bindable]
    private var price:String = String(dollars);
    [Bindable]
    private var dollars: Number = 10.00;

    private function clickHandler():void{
    dollars = 20.00;
    }
    ]]>
    </mx:Script>

    <mx:Button label="Click Me" click="clickHandler()"/>
    <mx:TextArea id="txtArea" width="300" height="200" text="{price}"/>
    </mx:Application>

    Greg Lafrance Guest

  3. #3

    Default Re: Evaluating a variable that contains a variable

    You can do it like so.

    TS

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
    <![CDATA[

    [Bindable]
    private var price:String;
    private var currencyString:String = "dollars";
    private var dollars: Number = 10.00;

    private function clickHandler():void{
    price = this[currencyString];
    }
    ]]>
    </mx:Script>

    <mx:Button label="Click Me" click="clickHandler()"/>
    <mx:TextArea id="txtArea" width="300" height="200" text="{price}"/>
    </mx:Application>

    VarioPegged Guest

  4. #4

    Default Re: Evaluating a variable that contains a variable

    Greg and Vario, you have given me some ideas; I will work on it when I have time and report back if figure it out. Thanks very much for the help.

    Carlos
    cheftimo Guest

  5. #5

    Default Re: Evaluating a variable that contains a variable

    Normally I would tell you to simply use an object like...

    var price:Object = new Object();
    price.dollars = 10.00;

    BUT you're trying to bind to the value (ie. you need to detect the changes) in
    which case adobe (in their wisdom) has a great class called ObjectProxy. Use
    it the same way you would a var of type object BUT it will fire binding change
    events.

    var price:ObjectProxy = new ObjectProxy();
    price.dollars = 10;
    // or price["dollars"] = 10;

    then in your mxml
    <mx:Label text="{price.dollars}"/>
    note: you can't use the indexer (i.e. price[dollars]) because it won't detect
    binding changes this way.

    Unless I'm misunderstanding you then I think this should get you the desired
    results, or at least on track.

    ctzn99 Guest

Similar Threads

  1. #39634 [NEW]: session variable and normal variable
    By erhanbaris at gmail dot com in forum PHP Bugs
    Replies: 3
    Last Post: November 27th, 10:09 AM
  2. #39251 [NEW]: variable variable class array property is read only
    By taskfreak at gmail dot com in forum PHP Bugs
    Replies: 1
    Last Post: October 25th, 07:08 AM
  3. #22237 [Com]: PHP crashes when class references property using variable variable
    By rep at devdomain dot com in forum PHP Development
    Replies: 0
    Last Post: September 29th, 11:34 AM
  4. [PHP] evaluating dynamic variable
    By Matt Matijevich in forum PHP Development
    Replies: 4
    Last Post: September 2nd, 08:54 PM
  5. evaluating dynamic variable
    By Steve Goodman in forum PHP Development
    Replies: 0
    Last Post: September 2nd, 07:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139