Xml :: Flex - Access The Value Of An Attribute Using A String Variable?

Aug 1, 2011

Using e4x in flex:

var attr : String = "foo";
var xml : XML =
<resultSet>
<node foo="1"/>
</resultSet>;

How can I use the variable "attr" to access

xml.node.@foo

I thought I could do it with

xml.node.@[attr]

But this doesn't seem to work. How can I access this attribute by a dynamic value like this?

Both

xml.node.@[attr];

and

xml.node.attribute(attr);

work, as Constantiner suggested.

Updates:

Say I have an XMLList in this form:

var bar:XML =
<resultSet>
<node>value</node>
</resultSet>;

I want to filter the original xml above by matching "foo" attributes with the "value" from node in bar.

Essentially I want a sublist of the original xml such that

xml.node.@foo == bar.value

for each xml row in the original value

As Constantiner mentioned, I can filter the original list by the value in foo, but what if I want to filter on multiple values?

Can I do something like:

xml.node.(bar.node.contains(attribute(foo)) ? attribute(foo) : null);

Or perhaps a cleaner method instead of the null?

View 1 Replies


Similar Posts:


ActionScript 3.0 :: Flex Access Attribute Values Via Variable Name?

Feb 2, 2009

I have a flex app where I need to be able to access and modify component attributes using variable names.

eg, say I want to edit the text attributes of text label.

I am not sure what object or attribute will need to be updated until runtime.

Say I get passed the following variables:

var objId:String = "label1";
var objAtt:String = "text";
var objVal:String = "Hello World";

I need to take these and update the "text" property of label that has the ID "label1" to "Hello World".

I have tried different variations to accomplish this but am stuck One example is

this[objId][objAtt] = objVal;

View 2 Replies

Flex :: Access To Object Property When The Propety To Access To It's In A String Variable?

Oct 20, 2010

It's too complicate to explain but I'll give you an example

I have an AS3 ResultEvent Object and this object has several propeties which can be accessed by this like:event.result.name or event.result.age and, I have this String variable: eventProperty:String that contains "name" or "age" How do I access to event.result. with the variable?

View 2 Replies

Actionscript 3 :: Flex - Object Attribute / Variable Null

Jan 6, 2011

If I execute the code below in FlashBuilder, I get the following error (I translate it) TypeError: Error #1009: Access to an Attribute or Method of an null-Object is not possible. at components::NumDisplay()[srccomponentsNumDisplay.mxml:39] This line in NumDisplay.mxml is the problem:

[Code]....

View 3 Replies

ActionScript 2.0 :: Access Variable Name As String?

Jul 29, 2009

function fn1(var2)
{
//here i want to trace the name of var1....ie output: "var1"
}
fn1(var1);

how to trace the variable name i am passing to fn1 (ie. var1) as string?

ie. output shoud be

"var1"

ie i want to trace the name of argument variable i am passing

View 0 Replies

ActionScript 3.0 :: Access Variable Via String?

Mar 11, 2009

Is there a way to access a variable via a String? Something like this:

HTML Code:
var myVar1:Int = 1
var myVar2:Int = "myVar1" as variable name

This is obviously doesn't work (and in this case pointless), but is there a way to do this?

View 4 Replies

ActionScript 3.0 :: Access The Value Of A Variable Of Which Only Have The Name As String In A Function

Dec 29, 2009

my goal is to keep my output window organized so i can follow all my traces more easily. so i wrote a couple of custom functions to achieve that. one of them would be: to more easily trace the following variable for example

[Code]....

View 6 Replies

String :: Flex - Download A String Variable As A File To The Local Machine?

Sep 21, 2011

I have a String variable in my flex (flash builder 4) application containing CSV data. I need to allow the user to download this data to a local file. For example, giving them a "csv" button to click and it might present them with a save file dialog (and I would be sending the contents of my string variable).Is this possible / how ?I am using the ResuableFX component for the datagrid to csv. This the code I ended up with that works to save the string to a text file for the user (in a web browser):

var dg2CSV:DataGrid2CSV = new DataGrid2CSV();
dg2CSV.includeHeader=true;
dg2CSV.target=adgEncounters;

[code]......

View 1 Replies

Professional :: LoadVars Returning Escaped String - Variable Access Not Possible

Aug 21, 2010

I am fetching some variables from a URL and get the result. While I can iterate through it via e.g.:

[Code]...

View 7 Replies

Flex :: Event Metadata: Using Static Variable For "name" Attribute?

Jun 24, 2011

I want to use the Event metadata tags to show what types of event my control will dispatch. The syntax looks like:

<fx:Metadata>
[Event(name="eventName", type="MyEvent")]
</fx:Metadata>

It seems like a best practice in Flex/Actionscript to define static variables that define event names like so:

public class MyEvent extends Event
{
public static const EVENT_NAME:String = "eventName";
// Other stuff..
}

It's a great practice since the event name can change easily and not have to be modified throughout the code. So my question is: Is there any way to use this static const in my metadata event tag? I can't seem to do something like this:

<fx:Metadata>
[Event(name="{MyEvent.EVENT_NAME}", type="MyEvent")]
</fx:Metadata>

Am I just ignorant of the proper syntax to do this, or is it impossible? Seems like it's just asking for hard to find bugs if someone decides to change the const since it is not strongly typed here.

View 2 Replies

Flex :: Access Member Variable By Using A Variable In The Name?

Aug 17, 2009

How can I access the member variable of an object by using a variable in the name.Example:

Entries Object has properties 1, 2, 3, 4, 5.
Normally I would access them by
var i : int = Entries.1;

[code].....

View 1 Replies

Flex :: Get String Of Variable Name In ActionScript?

Jan 26, 2011

Does anyone know some ActionScript api to get String of a variable name like following:

var foo:int;
var variableName:String = getName(foo);
trace(variableName);

The console need to show "foo" as the result of trace(variableName);

View 2 Replies

ActionScript 3.0 :: XML - Access The Attribute Src From Img

May 14, 2011

I'm using to gather information from a RSS feed (I'm interested in the src content to display an image)

[Code]...

So far so good now the tricky part is that I want to access the attribute src from img. If i trace(p[0] is XML); i get true, but if I try to trace trace(p.img.@src); or for that matter trace(p[0].img.@src); I get nothing back what am I doing wrong?

View 5 Replies

ActionScript 3.0 :: How To Access Specific Attribute In XML

Aug 2, 2010

Suppose I have an xml looking like this?

Code:
var emp:XML =
<employees>
<employee id="6401" code="231">
<lastName>Wu</lastName>
<firstName>Erin</firstName>
</employee>
<employee id="6402" code="232">
<lastName>Wu</lastName>
<firstName>Erin</firstName>
</employee>
<employee id="6403" code="233">
<lastName>Wu</lastName>
<firstName>Erin</firstName>
</employee>; </employees>

How would I access the specific attribute "6403"? I tried sth like this but did not work :
"emp.employee[2].@id"

View 0 Replies

Flex - Embed Image With A String Variable Which Contains A Filename?

Jun 26, 2010

I try to embed images in a mx:tree:

<mx:Tree labelField="name" id="tree"
folderOpenIcon="@Embed(source='assets/images/test.png')"
folderClosedIcon="@Embed(source='assets/images/test.png')"
defaultLeafIcon="@Embed(source='assets/images/test.png')">
</mx:Tree>

This works fine, but I will embed the images with a String variable.

[Code]...

View 3 Replies

Flex :: Get A Substring From String Variable Which Is Having HTML Tags?

Mar 4, 2011

I have a string variable assigned with some Content in HTML format.[code]...

But in the output i am getting as This is <b. Basically it considering HTML related tags also as text. But my code has to omit the HTML tags while calculating sub string.

View 2 Replies

Xml :: Set A Variable Attribute Of A Xml Element?

Jan 28, 2010

How do you set a variable attribute of a xml element?This is what I expected to work:xmlElement.attribute(variableAttr) = "the variable attribute is set to this string";


However, I'm getting some error that this value can only be retrieved as a reference and not set.Ofcourse, the following does not work either as it will look for the attribute named "variableAttr" and not for the attribute named after the value of the variable variableAttr:

xmlElement.@variableAttr = "example";

View 2 Replies

ActionScript 3.0 :: Cannot Set E4X Attribute To Variable?

Dec 16, 2008

I have an XML file loaded at run time.Among others, it contains several nodes which contain a name attribute and a value attribute.I want to be able to select name by value and vice versa.If I try and trace out a name by selecting its value, I get exactly what I expected:

[AS]
trace( "NAME: " + SiteModel.instance.constants.(@value==section).@na me );
[/AS]

But, and this is what I've been screaming at for most of the morning,if I try and assign that name to a variable, and trace the variable, I get epic fail:

[AS]
var n:String = SiteModel.instance.constants.(@value==section).@na me;
trace( "NAME: " + n );
[/AS]

Trying to trace that variable results in a TypeError:

Code:
TypeError: Error #1010: A term is undefined and has no properties.This is stupifyingly ridiculous in my opinion,

View 13 Replies

Flex :: Set Name Property Of Spark State Declaratively To A String Variable Value?

May 20, 2011

I have spark States declared in mxml. I also have a class with string constants. I want my states names to match the string constants. Is it possible to do that directly in mxml and how? [code]...

View 1 Replies

XML Parse Error 4157: The Name Attribute Was Not Found On The String Element On Opening Program

Nov 16, 2009

Recently, whenever I open up the program I get an XML parse error in the output window that reads: *** XML Parsing Errors ***Line 4157: The name attribute was not found on the string element  <string playername="" tiptext="Specifies that the gradient use the reflect sprea... Line 4164: The tipText attribute was not found on the string element  <string playername="" ti`text="Lets the user drag the specified sprite." This is not specific to any .fla file, but seems to be related to Flash itself. The program seems to work fine otherwise. Can anyone shed some light on this?

View 1 Replies

Professional :: Access UserLabel Attribute In Flash Builder

Oct 14, 2009

Is there a way to access the d:userLabel attribute in Flash Builder? I want to use a number of different files created from Illustrator -> Catalyst -> Flash Builder

Looks like this:
<fx:DesignLayer d:id="2" d:userLabel="A1">
<s:Rect d:userLabel="R_1" x="150" y="200" width="500" height="300" ai:knockout="0">
<s:fill><s:SolidColor color="0xffffff"/></s:fill></s:Rect>
<s:Rect d:userLabel="R_2" x="150" y="200" width="80" height="60" ai:knockout="0" >
</s:Rect>... </fx:DesignLayer>
 
Now the question:
Can I access the "userLabel" with a scriptfunction? Something similar to getElementByID? I want to change for example the fillcolor of a rect or path with that function. Because I have no id here I can't do something like:
R_1.fill = blue
And I don't want to manually change the files from Illustrator.

View 1 Replies

ActionScript 3.0 :: Get Attribute/variable Name At Runtime?

Aug 17, 2009

How would I get the name of the attribute/varialbe at runtime? For example if I have a variable defined like

var abc:String = '123'; From this, I would like to get the variable name, which is 'abc'.

View 4 Replies

Actionscript :: Flex - Access Variable From One Component Into Another?

Jul 18, 2010

I have a main application which has an int variable declared. I want to access this variable in another component which is present in another package. How can I do this?Main.mxml (default package)

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"

[code].....

View 4 Replies

Actionscript 3 :: Access The Width Attribute Of The Embed Object From Within Application Swf?

Apr 4, 2012

I have a flex 3 project with a root mx:Application. The width and the height are set to pct values, because the application has several sizes that can be chosen by the user, so the correct size is set on the embed's width attribute.

how to access the value in that attribute. I read in several places that this.root.loaderInfo.width should give me that value, but it always returns 500, which I am guessing comes from the default application container width [URL].

I realize I could pass it as a flashvar, but that is not a good solution in this case due to the nature of the project. I've also tried pplication.application.width, stage.width, and stage.stageWidth, to name a few. I can't depend on any of those values, since they change based on the browser zoom level.

View 2 Replies

ActionScript 2.0 :: Passing The Value Of An Attribute To A _global Variable

Aug 23, 2007

I need to pass the value of a attribute to a _global variable that can be accessed somewhere else in the movie.But it traces as undefined outside of onLoad.

eg.FRAME ONE

ActionScript Code:
var xml:XML = new XML();
xml.ignoreWhite = true;

[Code].....

View 3 Replies

ActionScript 2.0 :: Create A String Variable...and Then Use The Value Of That Variable To Declare Another Variable?

Jan 3, 2006

f you know PHP...then you know that you can create a string variable...and then use the value of that variable to declare another variable. like this:

PHP Code:

<?php$foo = "haha";$i{$foo} = "success";print $i{haha};?>

and it would display "success"...or like this:

PHP Code:

<?php$foo = "haha";$$foo = "success";print $haha;?>

and it would also display "success".

View 6 Replies

Flex :: How To Access Variable In Parent Component From Child

Sep 18, 2010

I have a public variable set within fx:Script tags in a parent component that I'd like to access directly from a child component. How can I do this? I don't want to pass the variable to the child component (I know how to do this and am currently using this approach). Following is a simplified version of the mxml:

Note: SimpleComp is an HBox with a couple of lists.
<mx:Accordion>
<comp:SimpleComp/>
</mx:Accordion>

View 4 Replies

ActionScript 3.0 :: Editing An Attribute/variable In A XML File Via Flash?

May 12, 2010

I'm working on a stand-alone application and NOT a web-based application, so I'm trying to do this strictly with AS3, if possible. For example, if I have an XML file that looks like this:

Code:
<profile>
<username>Joe</username>
<password>Smith</password>
</profile>

How do I change the value of the USERNAME attribute via AS3?

I've tried something like this already:

var xmlData:XML();
...
xmlData = XML(event.target.data);
xmlData.profile.username = "Mary";

but when I open the XML file, it's not writing "Mary" in place of "Joe."

View 9 Replies

ActionScript 2.0 :: String Variables - Consentrate A String To Call That Variable?

Mar 16, 2002

If i have an ASP page that is returning variables (and I can see them in the debugger) how do i consentrate a string to call that variable?

ie:
variables being returned are named:
"res1", "res2", "res3"...etc
for (var i = 0; i < 10; i++) {

[Code]...

View 4 Replies

Regex :: Replace Portion Of String With A Variable String?

Feb 10, 2012

Trying to replace a portion of a string with a "-" if it matches a string variable in AS3.

var re:RegExp = new RegExp(imageArray[j][1],"gi"); trace(imageArray[jTemp][2].replace(re,"-"));

imageArray[jTemp][2] is a string imageArray[j][1] is a string as well I'm not getting the result I expect. I would like trace above to return 'permanentContainer-' Here are the traces for the above variables

permanentContainer-temporaryContainer- temporaryContainer

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved