petersego
asked on
How do I assign xml attributes
How do I set the quotes in my xml-string to create attributes.
In the example below the id in the brackets will simply show as is, not as the actual id-number.
Something like
In the example below the id in the brackets will simply show as is, not as the actual id-number.
newfile = <item id="{id}"><name>{xmlsetName}</name><age>{xmlAge}</age></item>;
How do I set the quotes correct.Something like
<item id=+"{id}"+>
ASKER
Thanks, but I would prefer to keep my syntax - not makiing it a string..
It works fine as long as I only use nodes and is going to be send through php.
What Im looking for is the right syntax """{id}"""
It works fine as long as I only use nodes and is going to be send through php.
What Im looking for is the right syntax """{id}"""
In Flash the bindlable {} will not work, its for Flex I guess.
Hence then try creating a XMLNode and using appendChild and adding attributes to the nodes.
Warm Regards
Deepanjan Das
Hence then try creating a XMLNode and using appendChild and adding attributes to the nodes.
Warm Regards
Deepanjan Das
ASKER
Oh yes, it works. Originally I had the id in a node, and that worked flawlessly.
What Im trying to do is to check if an id-number is in an xml-file. If it is, I want the corresponding name and age placed in each a dynamic textfield.
else I want to generate an id-number and place som input-textfields.
And thats where newfile is relevant.
My problem is that I cant get the if else work.
if the "id" doesnt exist, the else-part isnt executed.
newfile = <item><id>{id}</id><name>{xmlsetName}</name><age>{xmlAge}</age></item>;
but since I want to catch the corresponding nodes of the id, I assumed it would be better to place it in an attribute of the parentnode item.What Im trying to do is to check if an id-number is in an xml-file. If it is, I want the corresponding name and age placed in each a dynamic textfield.
else I want to generate an id-number and place som input-textfields.
And thats where newfile is relevant.
My problem is that I cant get the if else work.
if the "id" doesnt exist, the else-part isnt executed.
That is really cool that you can use Bindable parenthesis {} in Flash, please may I know which version are you using in Flash IDE?
And can you share your code snippet of where you used the if else condition.
Warm Regards
Deepanjan Das
And can you share your code snippet of where you used the if else condition.
Warm Regards
Deepanjan Das
ASKER
Well, Im still on CS4.
I might return with the if else problem. Something is definitively wrong...
But if you would check it, I'd be gratefull.
I might return with the if else problem. Something is definitively wrong...
But if you would check it, I'd be gratefull.
myXML = XML(myxmlLoader.data);
idLength=myXML.item;
for (var i:int; i < idLength.length(); i++ ) {
if (idLength[i].id==id){
nametxt.text=idLength[i].(id==id).name;
agetxt.text=idLength[i].(id==id).age;
}
else{
nametxt.text="Input your name";
agetxt.text="input your age";
}
and the xml<?xml version='1.0' encoding='utf-8'?>
<items>
<item>
<id>106BB10495</id>
<name>James</name>
<age>65</age>
</item>
<item>
<id>9915R72620</id>
<name>Jerry</name>
<age>87</age>
</item>
<item>
<id>013R293445</id>
<name>Jimmy</name>
<age>22</age>
</item>
</items>
In your comparison:
Warm Regards
Deepanjan Das
if (idLength[i].id==id)
where will the variable "id" come from?Warm Regards
Deepanjan Das
ASKER
id wil come from flashvars.
ASKER
It seems that I cant iterate. If is only correct, if the correct id is placed first in the xml.
Try this:
Warm Regards
Deepanjan Das
myXML = XML(myxmlLoader.data);
nametxt.text="Input your name";
agetxt.text="input your age";
nametxt.text = myXML.item.(id == flashVarId).name;
agetxt.text = myXML.item.(id == flashVarId).age;
Warm Regards
Deepanjan Das
ASKER
Ahh, okay, I dont have to iterate.
That helped on getting the correct id, nomatter where it was in the xml, but Im still having problems with the else part. If it isnt comparable to any id in the xml, nothing happens.
That helped on getting the correct id, nomatter where it was in the xml, but Im still having problems with the else part. If it isnt comparable to any id in the xml, nothing happens.
if(myXML.item.(id == flashVarId)){
nametxt.text = myXML.item.(id == flashVarId).name;
agetxt.text = myXML.item.(id == flashVarId).age;
}
else{
nametxt.text="Input your name";
agetxt.text="input your age";
}
if flashVarId doesnt exist in xml, nothing will show in the textfield.
If you use my script under ID:34949282, then you will not have to write the else part.
This is because, by default the values are set first, then the actual values are set based on id match.
So if the ids do not match nothing happens and the default values are set.
Warm Regards
Deepanjan Das
This is because, by default the values are set first, then the actual values are set based on id match.
So if the ids do not match nothing happens and the default values are set.
Warm Regards
Deepanjan Das
ASKER
Well, in fact Im not only setting new values to the textfield, Im also changing the textfield to inputtype with borders and other input-features like eventlisteners
so in reality it will be looking like this:
var nametxt:TextField=new TextField();
var agetxt:TextField=new TextField();
inputTF();
valuesTF(); //This is if the FlashVarsId is present in the xml
addChild(nametxt);
addChild(agetxt);
which again results in that nothing happens if the FlashVarsId isnt present in the xml
so in reality it will be looking like this:
var nametxt:TextField=new TextField();
var agetxt:TextField=new TextField();
inputTF();
valuesTF(); //This is if the FlashVarsId is present in the xml
addChild(nametxt);
addChild(agetxt);
which again results in that nothing happens if the FlashVarsId isnt present in the xml
function inputTF(){
nametxt.x=100;
nametxt.y=58;
nametxt.width=190;
nametxt.height=18;
nametxt.border=true;
nametxt.borderColor=0x666666;
nametxt.selectable=true;
nametxt.background=true;
nametxt.type = TextFieldType.INPUT;
nametxt.text="Input your name";
nametxt.setTextFormat(preInputFormat);
nametxt.addEventListener(Event.CHANGE,updatetext);
nametxt.addEventListener(MouseEvent.CLICK,removeNameText);
agetxt.x=100;
agetxt.y=83;
agetxt.width=190;
agetxt.height=18;
agetxt.border=true;
agetxt.borderColor=0x666666;
agetxt.selectable=true;
agetxt.background=true;
agetxt.type = TextFieldType.INPUT;
agetxt.text="Input your age";
agetxt.setTextFormat(preInputFormat);
agetxt.addEventListener(Event.CHANGE,updatetext);
agetxt.addEventListener(MouseEvent.CLICK,removeAgeText);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you really much. I know that the question ended up far from the original, so I really appreciate it.
My Pleasure :)
Warm Regards
Deepanjan Das
Warm Regards
Deepanjan Das
Warm Regards
Deepanjan Das