Solved

Pass a Variable INTO Xml

Posted on 2010-09-07
3
387 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
Comment Utility
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
Comment Utility
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
Comment Utility
Great job.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now