Hey Glen,

It's quite simple actually, just use [brackets]. Look at the below code:

var xml:XML = <subscribeable>
  <object>
    <id>1</id>
    <name>system_management</name>
    <notifications>
      <notification>
        <id>1</id>
        <name>status</name>
      </notification>
    </notifications>
  </object>
  <object>
    <id>17</id>
    <name>sequence_management</name>
    <notifications>
      <notification>
        <id>1</id>
        <name>status</name>
      </notification>
      <notification>
        <id>2</id>
        <name>play</name>
      </notification>
      <notification>
        <id>3</id>
        <name>stop</name>
      </notification>
    </notifications>
  </object>
 </subscribeable>


 var nodeName:String = "name";
 trace(xml.object[nodeName]);


And if you want to use dynamic attributes, you do something like:

trace(xml.object.(@[nodeName]=="value"));

- Taka

On Wed, Sep 9, 2009 at 5:05 AM, Glen Pike <[email protected]> wrote:

> Hi,
>
>   I am having some issues with e4x filtering when I try and use a "dynamic"
> element in my expressions...
>
>   Using the XML below (somewhat truncated) I am trying to match either the
> "id" or the "name" depending on the variable type passed in:
>
>  private function _subscriberEventNameFromIds(objId:* = 0, funcId:int = 0,
> is_func:Boolean = true):String {
>           var objName:String;
>           var funcName:String;
>           //_subscriptionList contains the XML below...
>           //....
>           var obj:XMLList;
>           var idx:String = "name";
>                     if(objId is int) {
>               idx = "id";
>
>           }
>            //The following expression does not work, I cannot use idx
> "dynamically"..
>           obj = _subscriptionList.object.(child(idx) == objId);
>            //..., instead I have to do the following.
>            /*
>           if(objId is int) {
>               idx = "id";
>               obj = _subscriptionList.object.(child("id") == int(objId));
>           } else {
>               obj = _subscriptionList.object.(child("name") ==
> String(objId));
>           }
>            */
>      }
>
>   Does anyone know if /how I can do this dynamically?
>     Glen
>
>   <subscribeable>
>   <object>
>     <id>1</id>
>     <name>system_management</name>
>     <notifications>
>       <notification>
>         <id>1</id>
>         <name>status</name>
>       </notification>
>     </notifications>
>   </object>
>   <object>
>     <id>17</id>
>     <name>sequence_management</name>
>     <notifications>
>       <notification>
>         <id>1</id>
>         <name>status</name>
>       </notification>
>       <notification>
>         <id>2</id>
>         <name>play</name>
>       </notification>
>       <notification>
>         <id>3</id>
>         <name>stop</name>
>       </notification>
>     </notifications>
>   </object>
>  </subscribeable>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to