Solved

Pass a Variable INTO Xml

Posted on 2010-09-07
3
393 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
parsing xml using powershell 6 51
Replace value 2 55
Need a script that will create its own directory to dump logs into 7 51
script to read text file 34 29
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

734 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