using string variable to define object

Ask a Question related to Macromedia Flex General Discussion, Design and Development.

  1. #1

    Default using string variable to define object

    Hey guys,

    im having trouble getting this code to work. I would really appreciate any
    help you can provide as its the only thing holding me back from finishing my
    project :-). what im doing is creating a map where when you click on a state,
    it brings up all the locations we have within that state. the locations for
    each state are within an xml file.

    the file has the following structure. it is just a list of locations within
    different states. i used the each state's two letter code for the structure.
    [Q]
    <venuelist>
    <mi>
    <name></name>
    <address></address>
    <city></city>
    </mi>
    <mi>
    <name></name>
    <address></address>
    <city></city>
    </mi>
    <ma>
    <name></name>
    <address></address>
    <city></city>
    </ma>
    </venuelist>[/Q]

    here is the result handler. right now it is set so that it always grabs the
    locations from michigan
    [Q] public function resultHandler(event:ResultEvent):void {
    var arrvar:Object = event.result.venuelist.mi;
    arrcol = arrvar as ArrayCollection;
    dg.dataProvider = arrcol;
    }[/Q]

    in my flex, i have a http service calling the xml file and assigning the
    entire xml collection to a variable. and then having it assigned as the
    dataprovider for my datagrid. when you click on a state, it creates a pop up
    with the data grid. i also have an alert that shows the two letter state code
    you click on
    [Q] public function createPopUp(event:USAMapEvent):void {
    var stateSelected:String = event.code;
    Alert.show(stateSelected, 'Alert Box', mx.controls.Alert.OK);
    PopUpManager.addPopUp(panel, this, true);
    PopUpManager.centerPopUp(panel);
    }[/Q]

    what i need to do is set the dataprovider for the datagrid to something like
    dg.dataProvider = arrcoll + stateSelected so that it will go to "
    "venuelist.stateSelected". what is the proper way to do this. any help is
    appreciated!

    Jaguar280 Guest

  2. Similar Questions and Discussions

    1. #40137 [Opn]: in-function-call variable-define bug
      ID: 40137 User updated by: kolypto at mail dot ru Reported By: kolypto at mail dot ru Status: Open Bug Type: ...
    2. drop down menu to define a variable
      I'm using php to allow users to upload pictures onto their site. This works fine but I want to define a variable by using a drop down list. the...
    3. define variable problem
      I am attaching values to a array from XML. When I trace the variable the output gives me the values, no problem so far. the values are always...
    4. How to define a member variable?
      PHP barfs (on line 3) when I define a member variable like this: class Foo() { $num; function DoSomething() { $num = 2 + 3;
    5. template parameters : define a new variable?
      If you want to avoid having a "Whole-Bunch-of-Long-Multiple-If-Statements" so that you can have pretty good idea of what your page looks like,...
  3. #2

    Default Re: using string variable to define object

    Use resultFormat="e4x" in your HTTPService. Declare a property to hold the
    result...

    private var xml:XML;

    Then your result handler might look something like this...

    private function resultHandler(event:ResultEvent):void {
    xml = event.result as XML;
    }

    Your data provider for the datagrid will be an XMLList, so declare that as a
    bindable property...
    [Bindable]
    private var dp:XMLList;

    And then you'll assign it a value dynamically when a user clicks a state...

    public function createPopUp(event:USAMapEvent):void {
    var stateSelected:String = event.code;
    dp = xml[stateSelected] as XMLList; //define your datagrid's data provider
    dynamically based on the code
    Alert.show(stateSelected, 'Alert Box', mx.controls.Alert.OK);
    PopUpManager.addPopUp(panel, this, true);
    PopUpManager.centerPopUp(panel);
    }

    TS

    VarioPegged Guest

  4. #3

    Default Re: using string variable to define object

    Hey Variopegged!

    thank you so much for the reply! i follow your logic. i made the changes and
    everything works just like its supposed to :-). thank you once again... ive
    been messing with this issue for such a long time!

    Jaguar280 Guest

Posting Permissions

  • You may not post new threads
  • You may 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