Solved

Pass a Variable INTO Xml

Posted on 2010-09-07
3
390 Views
Last Modified: 2012-05-10
I have an ActionScript in Flash and an XML file that are working together.

I've set up my variables and such, and then I want to loop through them and add something to each "record." So I can do something like this:

for each (var object:XML in xml.*) {

                  object.appendChild(<myId>my id is here</myId>);
                  trace(object);
      }

That will add a new line in each item like so:
<myId>my id is here</myId>

Now, I obviously don't want to write "my id is here" as the value between the <myId> tags. The problem is I want to do something using a foruma or method or something to get a unique value there.

For example,  I'd like to do something like this...

object.appendChild(<myId>object.childIndex()</myId>);


...where the theory is that it returns the child index number of the object, so the fist item  would be appended with <myId>0</myId> and the second would be <myId>1</myId> and the third would be <myId>2</myId> and so on and so forth.

The problem is that it's writing everything as a string. It's actually writing out <myId>object.childIndex()</myId> for all of them,

I even tried doing something in ActionScript first, where I'd go:

var i;

and then push a value into the i variable via an incremental loop and then I would try

object.appendChild(<myId>i</myId>);

But, again, it just writes in "i" and not the value of i.

I need a way to say, "Calculate this part between the brackets."

Can anyone help? Is it possible? Is there another way around it?
0
Comment
Question by:caf210
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
ActionScript_Helper earned 500 total points
ID: 33624989
Here's an sample, it will append the new node. But see how we are concatenating string and variable.
---------------
var node:XMLList = new XMLList("<myId>" + i + "</myId>");
object.appendChild(node);

-------
0
 

Author Comment

by:caf210
ID: 33628622
ActionScript_Helper,

Yup, that's it. Exactly what I need.

Thank you much! I will accept as the solution and award the points.
0
 

Author Closing Comment

by:caf210
ID: 33628626
Great job.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question