actionscript help needed

  • codesecret
  • Beginner
  • Beginner
  • codesecret
  • Posts: 43

Post 3+ Months Ago

Could someone point me to resources with info on reading and implementing XML into ActionScript (flash) applications. I don't mean you should just make a google search on "Read XML in ActionScript". Also, what is your favourite XML editor and why? I tryied XMLSpy but there are some major limitations in the Home Edition.

I appreciate your help!
  • Belk Media Group
  • Graphic Monk
  • Professor
  • User avatar
  • Posts: 777
  • Loc: In the heart of California, Fresno.

Post 3+ Months Ago

codesecret wrote:
Could someone point me to resources with info on reading and implementing XML into ActionScript (flash) applications. I don't mean you should just make a google search on "Read XML in ActionScript". Also, what is your favourite XML editor and why? I tryied XMLSpy but there are some major limitations in the Home Edition.

I appreciate your help!


Well what do you want? That is a pretty broad request not to mention you put a limitation on it. I suppose you should look in the help section of your Flash app. or you could go to Actionscript.org

My favorite xml editor is TextEdit (NotePad) on Windows PC.
  • dhonsvick
  • Beginner
  • Beginner
  • dhonsvick
  • Posts: 49

Post 3+ Months Ago

XML and Actionscript is like peanut butter and Jelly =) here is an example

First off best XML editor is Dreamweaver in my book, but in all honesty notepad is pefectly ok....in my uses I have PHP, ColdFusion or Ruby actually write the XML. In this example we will work from a flat file.

1) Make a XML file called jelly.xml. the code for this file is as follows

Code: [ Select ]
<?xml version="1.0" encoding="iso-8859-1"?>
<jelleybeans>
   <bean color="green" flavor="lime" />
   <bean color="orange" flavor="orange" />
   <bean color="yellow" flavor="lemon" />  
</jellybeans>
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <jelleybeans>
  3.    <bean color="green" flavor="lime" />
  4.    <bean color="orange" flavor="orange" />
  5.    <bean color="yellow" flavor="lemon" />  
  6. </jellybeans>


2) Now for the Actionscript Magic.

Make an Label the first layer "Actions" and lock it. click in the first frame and go to the actions panel and lets get started. Save the flash file into the same directory as the xml file, name doesnt matter.

3)
Here is some example code

Code: [ Select ]
var jb:XML = new XML();
jb.ignoreWhite = true;

jb.onLoad = function(){
    trace(jb.firstChild.childNodes);
    var jbeans:Array = jb.firstChild.childNodes;
    for(var i=0; i<jbeans.length; i++){
        trace("The "+jbeans[i].attributes.color + " ones Taste Like "+jbeans[i].attributes.flavor);
    }
}

jb.load("jelly.xml");
  1. var jb:XML = new XML();
  2. jb.ignoreWhite = true;
  3. jb.onLoad = function(){
  4.     trace(jb.firstChild.childNodes);
  5.     var jbeans:Array = jb.firstChild.childNodes;
  6.     for(var i=0; i<jbeans.length; i++){
  7.         trace("The "+jbeans[i].attributes.color + " ones Taste Like "+jbeans[i].attributes.flavor);
  8.     }
  9. }
  10. jb.load("jelly.xml");



Now lets step through this

First thing you have to do is create an instance of the XML class
Code: [ Select ]
var jb:XML = new XML();

in this example we did this and assigned it to the variable "jb" which is "Typed" as XML.

Next we just remove the white space to make the file easier to work with.
Code: [ Select ]
jb.ignoreWhite = true;



We Call the file
Code: [ Select ]
jb.load("jelly.xml");


Then when it is loaded we do stuff

Code: [ Select ]
jb.onLoad = function(){
    trace(jb.firstChild.childNodes);
    var jbeans:Array = jb.firstChild.childNodes;
    for(var i=0; i<jbeans.length; i++){
        trace("The "+jbeans[i].attributes.color + " ones Taste Like "+jbeans[i].attributes.flavor);
    }
}
  1. jb.onLoad = function(){
  2.     trace(jb.firstChild.childNodes);
  3.     var jbeans:Array = jb.firstChild.childNodes;
  4.     for(var i=0; i<jbeans.length; i++){
  5.         trace("The "+jbeans[i].attributes.color + " ones Taste Like "+jbeans[i].attributes.flavor);
  6.     }
  7. }



Now all of the Contents of the XML file is contained in the variable "jb"
if you were to trace(jb); you would see the file.

NOw lets get to some methods of the XML class/

firstChild this goes to the first Node of the XML file

childNodes is an Array Object this will list all of the childNodes to a particular Node - It will report Null if empty

node.attributes will have all attributes for the node. You may call them by name

Now lets look at the XML file so that we can see how these work

Code: [ Select ]
var jbeans:Array = jb.firstChild.childNodes;
// we assigned the childNodes to a variable for ease of addressing

//and then we just loop through it
    for(var i=0; i<jbeans.length; i++){
        trace("The "+jbeans[i].attributes.color + " ones Taste Like "+jbeans[i].attributes.flavor);
    }
  1. var jbeans:Array = jb.firstChild.childNodes;
  2. // we assigned the childNodes to a variable for ease of addressing
  3. //and then we just loop through it
  4.     for(var i=0; i<jbeans.length; i++){
  5.         trace("The "+jbeans[i].attributes.color + " ones Taste Like "+jbeans[i].attributes.flavor);
  6.     }




Just a short Primer - Check out gotoandlearn.com has some great examples
  • codesecret
  • Beginner
  • Beginner
  • codesecret
  • Posts: 43

Post 3+ Months Ago

I have got the point....
  • Sumen
  • Proficient
  • Proficient
  • User avatar
  • Posts: 421
  • Loc: Rochester or Albany, NY

Post 3+ Months Ago

Honestly the first page that turned up after searching for XML and AS3 was actually a very good starting point for me.
http://www.kirupa.com/developer/flashcs ... s3_pg1.htm
As for an XML client, I use FlashDevelop (it highlights and auto completes XML as well as action script). Its an amazing actionscript editor.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 6 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.