Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Xml Attribute Values?



Quick one, I'm having trouble getting a specific attribute my xml. Is there an easy way to say if the attribute value = 1234 then return its nodevalue


myXML = new XML();
myXML.load("sample.xml");
myXML.ignoreWhite = true;
myXML.onLoad=feeds;

function feeds(){
myroot = myXML.firstChild;
people = myroot.firstChild;
students = people.childNodes;
if(students.attributes.id == '1234')
{
trace('yes record found')
}
}

the xml at the students level lookss like this

<student id="2214">
<name></name>
</student>
<student id="1234">
<name></name>
</student>
<student id="4567">
<name></name>
</student>


thanks



ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 04-02-2007, 09:29 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

XML > How To Get Attribute Values?
Hi,

I got a simple xml file:

Code:
<slideshow>

<slide>
<image_url="images/plant1.jpg" duration="2" />
</slide>

<slide>
<image_url="images/plant1.jpg" duration="4" />
</slide>

<slide>
<image_url="images/plant2.jpg" duration="6" />
</slide>

</slideshow>
I got this code:


Code:
var slide = xmlData.firstChild.firstChild.firstChild;
trace (slide);
which outputs:
<image_url="images/plant2.jpg" duration="6" />

But i want to output the value of image_url and duration... does anyone know how to do this?

Regards,

Vic.

Getting XML Attribute Values
Hello, I have this XML file:


Quote:




<?xml version="1.0" encoding="utf-8"?>
<winners>
<thunder5 name="Jonny James" place="Finished 3rd" about="Good, unique racing skills" />
</winners>




And this actionscript (2.0):

Quote:




var my_xml = new XML();
my_xml.onLoad = function(success) {

if (success) {

trace(my_xml.<stuff_to_change>);

}

};
my_xml.load("belekas.xml");




What shoud I write instead of "<stuff_to_change>" to get flash to trace "Jonny James", or "Good, unique racing skills"?

Thanks for your help,
AJSimpson

Changing Attribute Values E4X
Hi,

I am loading an xml file into flash and trying to change the attribute values within flash.

I can change one value like this:

Code:
extraXML.item[3].@newID=String(300);


This changes the attribute value of the 'id' attribute in the fourth node just fine into '300'.

But when I try to do this for all the nodes, like:

Code:
for(var n:uint=0; n <extraXML.item.length(); n++){
trace(extraXML.item[n].@id)//traces the values correctly
extraXML.item[n].@id=String(n);
// or: extraXML.item[n].@id=n;

}

the values are being changed but come out messily organized, randomly as it seems. The idea is that I would like to number the id's from 0 to extraXML.item.length().

Must be missing something!

Thanks,

Jerryj.

Changing Attribute Values E4X
Hi,
I am loading an xml file into flash and trying to change the attribute values within flash.
I can change one value like this:

Code:
extraXML.item[3].@newID=String(300);
This changes the attribute value of the 'id' attribute in the fourth node just fine into '300'.
But when I try to do this for all the nodes, like:

Code:
for(var n:uint=0; n <extraXML.item.length(); n++){
trace(extraXML.item[n].@id)//traces the values correctly
extraXML.item[n].@id=String(n);
// or: extraXML.item[n].@id=n;
}
the values are being changed but come out messily organized, randomly as it seems. The idea is that I would like to number the id's from 0 to extraXML.item.length().

Must be missing something!

Thanks,
Jerryj.

Using XPath To Get 'attribute' Values
I think I'm possibly being dumb, but when I call an attribute value using something like  //item/enclosure/@url  
I always get back the whole thing, including the equals sign and quotes  eg:  ="http://etc.etc.etc.mp3"
 
Is there not a way for me to just get the url value, without the sign and quotes (in this example), or would I just have to strip out the chars I dont want?
 
 
seems weird, if I have to.

tia

Reading Values From Attribute With For Loop
Hi,
I want to read attributes values from an XML file using an array. Here is the sample script which narrates my problem. Its fetching the values from the first node only and displays the same values twice.
M
22/121980
M
22/121980

Somewhere i am making a mistake in this Loop..can anybody works out where????pls,,,thanx


var oXML = new XML();
oXML.parseXML("<reportdatas><reportdata gender="M" dateofbirth="22/12/1980" address="XYZ" /><reportdata gender="M"dateofbirth="12/05/1982"address="XYZ" /></reportdatas>");
// Grab attribute names
var a = oXML.firstChild.firstChild.attributes;
// Enumerate name/value pairs
len = oXML.firstChild.childNodes.length
//trace(len)
attValue = [];

for(i=0; i<len; i++){
for(att in a){
attValue[i] = eval("a." + att);
trace(attValue[i]);
}
}

Ashish

XML Attribute: How To List Values Without Duplicates
Using the XML below as an example, how would I list all the available countries, but without duplicates. Same for the "industry" attribute. I'm using MX 2004, btw.


Code:
<clientlist>
<item industry="retail" country="us">
<client>Albertsons Inc / Boise, ID</client>
<URL>http://www.albertsons.com</URL>
</item>
<item industry="business" country="canada">
<client>Albert Normandin Photography / Vancouver, BC</client>
<URL>http://www.albertnormandin.com</URL>
</item>
<item industry="business" country="israel">
<client>Amdocs Limited / Ra'anana, Israel</client>
<URL>http://www.amdocs.com</URL>
</item>
<item industry="education" country="greece">
<client>American College of Thessaloniki / Thessaloniki, Greece</client>
<URL>http://www.anatolia.edu.gr</URL>
</item>
<item industry="retail" country="canada">
<client>Meinhardt Fine Foods / Vancouver, BC</client>
<URL></URL>
</item>
<item industry="nonprofit" country="us">
<client>WITS / Chicago, IL</client>
<URL></URL>
</item>
<item industry="infocom" country="uk">
<client>XPO Networks Limited / London, UK</client>
<URL></URL>
</item>
</clientlist>
I'm attaching a file to mess around with if anyone cares.

Reading Values From Attribute With For Loop
Hi,
I want to read attributes values from an XML file using an array. Here is the sample script which narrates my problem. Its fetching the values from the first node only and displays the same values twice.
M
22/121980
M
22/121980

Somewhere i am making a mistake in this Loop..can anybody works out where????pls,,,thanx


var oXML = new XML();
oXML.parseXML("<reportdatas><reportdata gender="M" dateofbirth="22/12/1980" address="XYZ" /><reportdata gender="M"dateofbirth="12/05/1982"address="XYZ" /></reportdatas>");
// Grab attribute names
var a = oXML.firstChild.firstChild.attributes;
// Enumerate name/value pairs
len = oXML.firstChild.childNodes.length
//trace(len)
attValue = [];

for(i=0; i<len; i++){
for(att in a){
attValue[i] = eval("a." + att);
trace(attValue[i]);
}
}

Ashish

Objects With Mysterious Disappearing Attribute Values
Hi all,

New to actionscript and flash and would like to ask for a little help/advice:

I have been using flash 8 with actionscript to create an interface for a musical password system (yeh, just don't ask ;-) ) The interface is being used for a usability test that emails out the results to me at the end.

The problem is that I have an object called LoginSession that is constructed in frame one and it has a number of attributes including username and an array containing references to sounds used in each login session (i.e. different users have different sounds as the basis for their password alphabets). When I run the test in the flash "in built" viewer (sorry not sure what this is called) and firefox the variables are accessible in later frames, however in internet explorer the variables become "undefined" after the first frame.

I can supply code snippets, but thought this might be a common problem as I am not trying anything that is too out of the ordinary, so haven't bothered yet.. does this ring a bell with anyone - or does anyone have any ideas.

Thanks, M

Accessing Specific Attribute Values Anywhere Within An XML Tree Structure AS2?
I am loading in an XML document that has multiple nodes and childNodes throughout (the example is posted below). What I am trying to do is locate the value of a specific node attribute within the XML file. I tried using Xpath but could not get it to work.

xml sample
<SITE>
<MENU NAME="ARTS & ENTERTAINMENT">
<CATEGORY NAME="Portfolio" LINK="files/arts/portfolio/portfolio.swf">
</CATEGORY>
<CATEGORY NAME="Contact" LINK="files/arts/contact/contact.swf">
<SUB NAME="sub title 1" LINK="files/arts/contact/sub1/sub1.swf" />
<SUB NAME="sub title 2" LINK="files/arts/contact/sub2/sub2.swf" />
</CATEGORY>
</MENU>

<MENU NAME="AVIATION">
<CATEGORY NAME="Portfolio" LINK="files/aviation/portfolio/portfolio.swf">
<SUB NAME="Airports" LINK="files/aviation/portfolio/airports/airports.swf" >
<SUB2 NAME="Terminals" LINK="files/arts/portfolio/airports/term.swf"/>
</SUB>
<SUB NAME="Contact" LINK="files/aviation/portfolio/contact/contact.swf" />
</CATEGORY>
<CATEGORY NAME="Services" LINK="files/aviation/services/services.swf">
<SUB NAME="design" LINK="files/aviation/services/design/design.swf" />
<SUB NAME="Interior" LINK="files/aviation/services/interior/interior.swf" />
<SUB NAME="Plans" LINK="files/aviation/services/plans/plans.swf" />
</CATEGORY>
</MENU>
</SITE>

What I want to do is locate a specific node attribute such as the "LINK" attribute that has a specific value and then find that specific node's "NAME" attribute. But how do I locate such an attribute anywhere within the XML structure no matter how deep it goes?

Thank you for your help.

Assign XML Node Values Dependent On "id" Attribute In The XML File...
Here is what I am needing to do:
I have anywhere from 8-20 MCs (objects) on a screen. Each may or may not be visible, and each will be in a different location, independent of other MCs. The XML will assign values (X,Y, alpha, rotation, loadMovie, color, etc.) to each clip.

I know how to hard code each MC to the XMLNode in the file, but am wanting to have the id attribute ("id=object1", "id=object2", etc.) to determine which nodes/children to pull values from. IE, my MC called "quoteOfTheDay", I want to read the values from the XML node with the id="quoteOfTheDay". And so on...

Does anyone have an idea how to do this? I'm thinking a loop that pulls all attributes named id, or something?

anyone...

thanks


my XML
////////////////////////////////////////////
<objects backgroundImage="bg1.jpg" >
<object id="object1">
<visible>1</visible>
<xPos>80</xPos>
<yPos>40</yPos>
<alpha>80</alpha>
<textContent>Number 1</textContent>
</object >
<object id="object2">
<visible>1</visible>
<xPos>400</xPos>
<yPos>40</yPos>
<alpha>20</alpha>
<textContent>Number 2</textContent>
</object >
<object id="object3">
<visible>1</visible>
<xPos>500</xPos>
<yPos>130</yPos>
<alpha>80</alpha>
<textContent>Number 3</textContent>
</object >

</objects>

////////////////////////////////////////////

Generating Random Values For A Variable While Excluding The Already Generated Values
Hey Flashers:

Here's my question this time around. I want to generate random values between 1and 50 for a variable but I want every time I generate the new value to exclude the already generated values from the pool of options. Something like playing the lottery where no two drawn numbers can be the same. Any hints or references to open code will be greatly appreciated.
As always, thanks a lot!

Function Populated By Node Values Returning Undefined Values
I have been working on some code which extracts the information from an xml document, styles it with css and then loads the various node values into a text field and arrays. The user click on a link in the text field which calls myFunction using asfunction and that in turn should enter the array values relating to that link into text fields.

Everything in general seems to work OK except the value that is returned to the two text fields on pressing the link in the CCTextField "which in turn calls myFunction" returns undefined for those values of the arrays. I check the agency[2] value in the function that populates the arrays and the value is returned as it shoiuld be so it appears there must be something amiss with myFunction, or at least it would seem so.

Any takers as to what this problem might be?

I have supplied some shortened code below.


PHP Code:



CCTextField.styleSheet = myStyle;
// NOTE: CCTextField styleSheet has been created beforehand
my_xml = new XML();
// NOTE: my_xml has been created beforehand


my_xml.onLoad = function(sucess) {
    if (sucess) {
        processXML(my_xml);
    }
};
// Load up the XML file into Flash
my_xml.load('TEST.xml');
// This is the function that will be called when
// the XML document is loaded succesfully
function processXML(xmlDoc_xml) {
    
    var listText_comm = ""; // List text variable
    var entryNum = 0; // Entry number variable
    var agency = new Array(); // Agency array
    var production = new Array(); // Production array
    
    for (var n = 0; n<xmlDoc_xml.firstChild.firstChild.childNodes.length; n++) {
    
        categoryNodeName = xmlDoc_xml.firstChild.firstChild.childNodes[n].nodeName;
        
        if (categoryNodeName == "client") {
            listText_comm += "<a href='asfunction:_root.myFunction," + entryNum + "'>" + xmlDoc_xml.firstChild.firstChild.childNodes[n];
            trace("client " + xmlDoc_xml.firstChild.firstChild.childNodes[n]);
        } else {
            if (categoryNodeName == "title") {
                listText_comm += " - " + xmlDoc_xml.firstChild.firstChild.childNodes[n] + "</a>";
                trace("title " +xmlDoc_xml.firstChild.firstChild.childNodes[n]);
            } else {
                if (categoryNodeName == "agency") {
                    agency[entryNum] = xmlDoc_xml.firstChild.firstChild.childNodes[n].firstChild.nodeValue;
                    trace("agency " +xmlDoc_xml.firstChild.firstChild.childNodes[n].firstChild.nodeValue);
                } else {
                    if (categoryNodeName == "production") {
                        agency[entryNum] = xmlDoc_xml.firstChild.firstChild.childNodes[n].firstChild.nodeValue;
                        trace("production " +xmlDoc_xml.firstChild.firstChild.childNodes[n].firstChild.nodeValue);
                        entryNum++; // click over the entry number by 1
                    }
                }
            }
        }
    }
    
    trace("AGENCY 2 = " + agency[2]); // this returns agency number 2 OK
    
    _root.CCTextField.text = listText_comm; // CCTextField shows this text OK
}

function myFunction(listItem) {
    clientF = agency[listItem]; // THIS RETURNS undefined ON PRESSING THE LINKS IN CCTextField
productionF = production[listItem]; // THIS ALSO RETURNS undefined ON PRESSING THE LINKS IN CCTextField

    trace(listItem); // this trace = the list item passed by asfunction OK


[MX] Weirdness With Values Used By Array Populated Clip Values.
Hi,

I have used invisible buttons on top of some text, as part of a volume control interface.

The text buttons are set out as 0 – 25 – 50- 75 -100 referring to the % that a music tracks volume will change to once a button is pressed – so far so good.

Now to give values to the text buttons in order for them to make the text clip that they are on top of go to & stop & the right frame I have used arrays to give a reference the location of the text clip:

numbs_array = [_root.volHold_mc.vol0, _root.volHold_mc.vol25, _root.volHold_mc.vol50, _root.volHold_mc.vol75, _root.volHold_mc.vol100];

I then reference that in a home made “release” function as “this.monica.gotoAndStop(2);” “monica” being the reference to the address of the clip.

It all works fine except the code seems to make the movie play clips in an order that they have not been designated in the array – Like a button on top of the “25”% value will play the animation for the “75”% clip?

The whole problem is probably much better seen through the movie – the problem section of which i have attached below.

Passing Values From ASP To Change Alpha Values Etc
Is this possible? I currently have a log in system, logging each page a user visits, these visits amount to a value and have this value passed to flash to control alpha values, tints etc to reflect look and feel. is this possible?

Passing Values From ASP To Change Alpha Values Etc
I have posted this before, but wondering if anyone can help?

Is there anyway of having external values controlling alpha values, tints etc of a movieclip?

Database Values To Array Values
Hi all,

I've created a movie which uses a number of arrays to construct the elements of a flash-based gallery.

What I need is a practical method of getting values from a database into an array via an ASP page.

The plan was to load the variables into these arrays using the an asp page and a loadvars object to create a string (basically the array values in quotes separated by commas) which was then to be inserted into the parameters for the creation of the array. Needless to say this hasn't worked- the create array object seems to interpret the whole string as the first value in the array, i can't find a way of populating the array from just a single asp page.

I've given up with this method and really need a few pointers.

Thanks

How Do You Change Rgb Values Hexadecimal RGB Values?
how do you change rgb values hexadecimal RGB values in action script?

XML Attribute
Hi

can any one tell me how to retrive a particular attribute of an XML element using XML object in Flash.

Instead of looping through "for(attb in attributeElement)", I need to locate and read one amomg many attributes of the element, without looping through each attribute.

thx

Getting An Attribute Name From XML
Hi--

I'm importing an XML file into Flash and I want to be able to reference attribute names dynamically.

For example, let's say we have some XML:


Quote:




<root>
<car color="blue" type="honda" transmission="automatic" />
</root>




If I say:


Quote:




trace(myXML.firstChild.firstChild.nodeName);




I get a value of "car".

I understand that if I say:

Quote:




trace(myXML.firstChild.firstChild.attributes.color )




I'll get "blue"...

My question is: how can I retrieve the names: "car", "type" and "transmission"? ... i.e. the names of the variables (not their values of blue, honda, and automatic)??

Any help would be much obliged!!

Add Attribute To XML
Hi,
I'm currently using an XML file to load an image and menu-name into a list component and would like to add a description field to this.
I have added another attribute to my XML file called 'desc' so the file is now arranged:



Code:
<xml>
<listitem name="Le Mans 06, 0-5" url="http://www.dedicatedmicros.com/ukdir/FLVHUB/FLV/" thumb="1.jpg" desc="some text">
<stream name="1.FLV" start="0" len="-1"/>
</listitem>
After dropping a dynamic text field onto the stage instance named 'description', I have attempted to modify the xmllist.load code but despite not firing any errors, this has not resolved the issue:
That code is as follows: (changes are proceeded by '//-')


Code:
//-------------------------LIST SELECTION CHANGE-----------------------------
//Add an event listener on the list, when it triggers, run the listListener function to repopulate the list
list.addEventListener("change", listListener);


//Function that loads the XML file, parses it, and builds the list of available video clips
var xmllist = new XML(); //setup a variable to hold the XML
xmllist.ignoreWhite = true;
xmllist.load( "video_playlist.xml" ); //load the XML file
//The following gets called when the XML has been loaded
xmllist.onLoad = function( status ) {
if ( !status )
trace( status );
var entries = this.childNodes[0];
var playlists = {};
var nav = [];
//- var description = {};
//- var descrip = [];
for ( var i = 0; i < entries.childNodes.length; i++ ) {
var entry = entries.childNodes[i];
if ( entry.nodeName == "listitem" )
//builds array of video clip names
playlists[entry.attributes.name] = entry;
else if ( entry.nodeName == "menu" ) {
//builds array of available videos
for ( var j = 0; j < entry.childNodes.length; j++ )
nav[j] = playlists[entry.childNodes[j].attributes.name];

//- if ( entry.nodeName == "desc" ) {
//- //builds array of descriptions
//- description[entry.attributes.desc] = entry;
//- for ( var k = 0; k < entry.childNodes.length; k++ )
//- descrip[k] = //-description[entry.childNodes[k].attributes.desc];

}

} //end else if
} //end if

//sends the array of videos to the listbox UI
list.dataProvider = nav;
desc.text = descrip;
} //end xmllist.onload
Was hoping someone could help point me in the right direction as to where i'm going wrong with this one as i've attempted various things now but have not had success with any.

If anyone can offer any assistance here I would be very appreciative,

Thanks,
Dave

XML Attribute Ids
Is there a way that I can loop through the attributes of an XML node and return the id names of the attributes rather than their values?
It seems like it should be simple but I cant seem to get it (its been a long day).

Please help
Cheers

[Q] Getting The XML Attribute...
I must be missing something here... Somehow I cannot get the attribute of the XML node... Anybody see what I am missing???

ActionScript Code:
var _xml = new XML();
_xml.ref = this;
_xml.ignoreWhite = true;
_xml.onLoad = function (raw)
{
    if (raw)
    {
        trace(this);
        var _doc:XML = new XML(this);
        trace("_doc.firstChild = " + _doc.firstChild);
        trace("_doc.firstChild.attributes = " + _doc.firstChild.attributes);
        // assign the value of the 'name' attribute to variable y
        for (var i in _doc.firstChild.attributes)
        {
            trace (i + " : " + _doc.firstChild.attributes[i]);
        }
    }
}
_xml.load("test.xml");

Code:
<QuizData>
<Quiz
quizID="1"
quizText="Some text that goes with Quiz #1" />
</QuizData>
I get this in the Output panel...

Quote:




<QuizData><Quiz quizID="1" quizText="Some text that goes with Quiz #1" /></QuizData>
_doc.firstChild = <QuizData><Quiz quizID="1" quizText="Some text that goes with Quiz #1" /></QuizData>
_doc.firstChild.attributes = undefined

Can't Get XML Attribute
Hi
I got a XML File that looks like this:


Code:
<BODY>
<ATTACHMENTS>
<IMAGE ONLINE="0009068052_BLD_Online.jpg"
THUMBNAIL="0009068052_BLD_Thumbnail.jpg"
PLACE="Wien"
SOURCE="APA (dpa)">Das sind Neuigkeiten
</IMAGE>
</ATTACHMENTS>
</BODY>
Now in Flash i cant Access the Attribute Online, i load the xml file into AccountXML and then try to get it with trace but if i do this trace


ActionScript Code:
trace(AccountXML.BODY.ATTACHMENTS.IMAGE);

i get
"Das sind Neuigkeiten"
if i do this trace


ActionScript Code:
trace(AccountXML.BODY.ATTACHMENTS.IMAGE.attribute(ONLINE));

i get an error
How can i get the Online Attribute?
thx ecaos81

XML Help - Get Attribute Name
Is it possible to get the name of an attribute in one of the xml nodes?


Code:
<Book>
<chapter pages="30" source="test1.swf" >The First Chapter</chapter>
</Book>
For example, I know how to get the attribute("pages") value of 30. However, what if I don't know the attributes name? How can I retrieve it?

Thanks.

Xml Attribute Value
I'm having trouble getting a specific attribute value when
parsing the xml tree. I need to get the chidNode that matches my attribute
request. Is there an easy way to say if the attribute value = 1234 then return
its nodevalue


myXML = new XML();
myXML.load("sample.xml");
myXML.ignoreWhite = true;
myXML.onLoad=feeds;

function feeds(){
myroot = myXML.firstChild;
people = myroot.firstChild;
students = people.childNodes;
if(students.attributes.id == '1234')
{
trace('yes record found')
}
}

the xml at the students level lookss like this

<student id="2214">
<name></name>
</student>
<student id="1234">
<name></name>
</student>
<student id="4567">
<name></name>
</student>


thanks





























Edited: 04/02/2007 at 08:36:52 AM by m10461

Get XML By Value Of Attribute
Hi!

I'm updating an old AS2 project and have a question about XML. This thing I'm working on uses two xml files, pics.xml and lang.xml. The last one of the two contains translations for the flash file and looks like this:


PHP Code:



<lang>    <trans lang="sv">        <nextPic>Nästa bild</nextPic>            <prevPic>Föregående bild</prevPic>        <showMap>Visa karta</showMap>    </trans>    <trans lang="en">        <nextPic>Next picture</nextPic>            <prevPic>Previous picture</prevPic>        <showMap>Show Map</showMap>    </trans></lang> 




and in the pics.xml you choose what language to display by setting an xml attribute to either "sv" or "en".

My question is, how do I tell the function that parses lang.xml to only parse the node with the right language. If "sv" is set in pics.xml I only want to parse the first bit om lang.xml there, you se what I mean? I don't what to use something like: this.firstChild.childNodes[0].blahblah cos most likely the users of this will ad more languages...

Xml Attribute Name
is there a way to get attribute name from xml? I can't find any property that would return it...

ActionScript Code:
var x:XML = <aaa name="something"/>;

I need 'name' in this case...

ALT Attribute On SWF
Is it possible to add an alt tag to a flash movie?

Need To Get XML Attribute Name, Not Value
I need to be able to dynamically get the name of an attribute in AS3. So for example:

Code:

<setup>
   
   <animation speed=".5" />
   <animation transition="saturation" />
   <animation easetype="linear" />
   <animation clickthrough="true" />

</setup>

I need to be able to get that name of the first attribute of the first node, which is speed. Then transition, easetype and clickthrough. I can get the value of the attribute easily: myXML..animation.@speed.

I'm trying to basically use this xml file to make a content control interface of sorts. Where a user can dynamically change the xml content and save it to disk on a computer locally. But in order to do that I need to be able to get the attribute name. Any help would be great.

Thanks,
Chester Rivas

Reading An XML Attribute
I've got a few dynamic text fields that i want to build filled with certain info from an xml doc.
The xml doc is fine and it contains three different peoples names with an email aswell.
What i am trying to do is when a user clicks on a specific button, the relevant info for that button is loaded into the text fields.
What i can't get my head around, is how do i use action script to search through the xml do, and pick out the info it needs.
if anyone has a .fla i can have a look at, with also some advice i would be chuffed as beans!!!

hope somebody can help me cheers

lee

Attribute Used Outside Of Class
Hi Im getting this attribute used outside of class error, Im writing this fractal sub divide class and importing it into flash mx when i get the error any ideas??

thanks



class fractalsubdivide{

//Properties
public var XMID:Number;
public var YMID:Number;

public var i:Number;

public function fractalsubdivide(x1:Number,y1:Number,x2:Number,y2: Number,depth:Number,s:Number)
{

//depth is the depth of recursion
//s is the scale factor


//if the recursion stops we just draw the line segment
if(depth == 0)
{

temp1 = new Point2D(x1,y1);
temp2 = new Point2D(x2,y2);
temp1.drawline(temp2);

}
else
{
//we calculate the MID points

XMID = (x1 + x2)/2 + s*GAUSS;
YMID = (y1 + y2)/2 + s*GAUSS;

//draw the two halves

fractalsubdivide(x1,y1,XMID,YMID,s/2,depth-1);
fractalsubdivide(XMID,YMID,x2,y2,s/2,depth-1);

}

private function GAUSS()
{
GAUSS = 0;

for(i = 1; i < 6; GAUSS = GAUSS + Math.random() - Math.random())
{
GAUSS = GAUSS/6;
}
}

}



}

Attribute Used Outside Of Class
Im getting an attribure used outside of class error on this code..
any ideas ??

public class SnowFlake{


public var p1:Point2D;
public var p2:Point2D;
public var p3:Point2D;

public function SnowFlake(point1:Point2D,point2:Point2D,point3:Poi nt2D)
{

p1 = new Point2D();
p2 = new Point2D();
p3 = new Point2D();

p1.x = point1.x;
p1.y = point1.y;
p2.x = point2.x;
p2.y = point2.y;
p3.x = point3.x;
p3.y = point3.y;

}
public function SnowDraw()
{

frac1 = new FractalLineKoch(p1,p2)
frac1.drawKLine(3,0);

frac2 = new FractalLineKoch(p2,p3)
frac2.drawKLine(3,0);
}

}

Extract By Attribute From Xml
I have an xml file that contains url attributes with the value being a url (funnily enough!)

I just want to extract the url values to an array. Is there a way of doing this without having to navigate using node.childNode.... ?

Finding Attribute Name In Xml
I am trying to loop through an xml file and if a certain attribute is equal to a value then look through all the nodes that are children of it and use there values.


Where i am getting stuck is in the if statement. I tried the following and it doesn't seem to work.

The xml loads fine and i have gotten it to parse out in other areas its just getting it to parse if an attribute == to something then do the following.

Where did i go wrong?

part of my xml code

Code:
<Buttons>
<BtnGroup name="iconic" prevUrl ="images/styles/previews/buttons/btn_Iconic/btn_Iconic_musUp.png">
<btn name="musicBtn" upUrl="images/styles/components/buttons/btn_Iconic/btn_Iconic_musUp.png" overUrl="images/styles/components/buttons/metalGrain/musicOver.png" />
<btn name="picsBtn" upUrl="images/styles/components/buttons/btn_Iconic/btn_Iconic_picUp.png" overUrl="images/styles/components/buttons/metalGrain/picsOver.png"/>
<btn name="videoBtn" upUrl="images/styles/components/buttons/btn_Iconic/btn_Iconic_vidUp.png" overUrl="images/styles/components/buttons/metalGrain/videosOver.png"/>
<btn name="downloadBtn" upUrl="images/styles/components/buttons/btn_Iconic/btn_Iconic_dlUp.png"
overUrl="images/styles/components/buttons//metalGrain/dlOver.png"/>
</BtnGroup>

<BtnGroup name="globalBtns">
<btn name="shareBtn" position="br" upUrl="images/styles/components/global/Btn_ShareBtmR_Up.png" overUrl="images/styles/components/global/Btn_ShareBtmR_Over.png"/>
<btn name="chatBtn" upUrl="images/styles/components/global/btn_ChatUp.png" overUrl="images/styles/components/global/btn_ChatOver.png"/>
<btn name="feedBtn" upUrl="images/styles/components/global/btn_FeedUp.png" overUrl="images/styles/components/global/btn_FeedOver.png"/>
<btn name="previewBtn" upUrl="images/styles/components/global/btn_infoUp.png" overUrl="images/styles/components/global/btn_infoOver.png"/>
<btn name="previewBox" upUrl="images/styles/components/global/PreviewBox.png"/>
<btn name="infoBtn" upUrl="images/styles/components/global/btn_infoUp.png" overUrl="images/styles/components/global/btn_infoOver.png"/>
</BtnGroup>
</Buttons>
actionscript code

Code:

var xmlBtnGroup = xml.Buttons.BtnGroup;

function btnOptions_Click(event:MouseEvent):void {
currentBtn = event.currentTarget;
oldBtnName = currentBtn.name.indexOf("Btn");
newCurrentBtn = currentBtn.name.substr(0, oldBtnName);
panel_mc.nextBtn.enabled=true;

if("@name" in xmlBtnGroup){
}
trace(xml.Buttons.BtnGroup.(hasOwnProperty("@name") && @name == "globalBtns"))


for (var i:uint=0; i < xmlBtnGroup.length(); i++) {
// this gets the correct values
if (xmlBtnGroup[i].@name == newCurrentBtn) {
urlToUse = url + xmlBtnGroup[i].btn.@upUrl;
musImgUrl = xmlBtnGroup[i].btn[0].@upUrl
picImgUrl = xmlBtnGroup[i].btn[1].@upUrl
vidImgUrl = xmlBtnGroup[i].btn[2].@upUrl
dlImgUrl = xmlBtnGroup[i].btn[3].@upUrl
}

// tried this and doesn't work
if ("@name" == "globalBtns" in xmlBtnGroup[i] ){
}


// also tried this
if (xmlBtnGroup[i].(attribute("name") == "globalBtns")){
}
}
I have tried all the ways to do it through an if statment that if a certain btnGroup name attribute is something then do the following but i can't seem to get it for the life of me.

Check If XML Attribute Is Set?
I have a piece of code where I want to set a variable from an XML attribute only if that attribute is defined, otherwise do nothing.

Compare the following xml snippets:
<component name="gun" size="0">
vs.
<component name="armor">

In the example above, the "gun" has set the size and the "armor" has not.

How can I check whether an XML item (such as the two components above) has set a particular attribute (such as size)?

Css Attribute Problem
Hello everyone,

I'm just starting out in actionscript and I'm trying to load an external css file into a dynamic text field. Everything is working fine except for the bold attribute on the CSS stylesheet. As soon as I apply span tag and the named class, the text I want to bold disappears?????

Here's the css file:

p {
font-family: "Bitstream Vera Sans";
font-size: 12px;
}
a:link {
color: #CC0000;
font-weight: normal;
text-decoration: underline;
}
a:hover {
color: #3F7FBE;
text-decoration: underline;
font-weight: normal;
}
.hilight {
font-weight: bold;
}
.alignRight {
text-align: right;
}
.colorBlue {
color: #3F7FBE;
}
And here's the span tag: info=<textformat leading="8"><p><span class="hilight">text:</span>
Any idea's?

One other thing, does anyone see a problem with this script:

var cssStyles:TextField.StyleSheet = new TextField.StyleSheet();
cssStyles.load("styles/styles.css");
cssStyles.onLoad = function (success) {
if (success) {
loadedInfo.styleSheet = cssStyles;
_level0.myLV.load("vars/ourHistory.txt");
} else {
loadedInfo.text = "There has been an error loading the requested information. Please contact the Webmaster and report your error.";
}
}
When I change the file name to test the error massage, it does nothing.
there has got to be something simple i'm missing. By the way, I'm using Flash pro 8 if that makes a differance. Please help. Thanks.

Sincerely,
jbg00d

Variable Name In Xml Attribute
Hello 2 problems the same day and it is sunday (;

this what i'm trying to do I'm tryin to do

I try to retrieve an attribute value with a variable called image_sub this variable is made like this:

image_sub = "sub_"+sub_number (let say sub_number = 2)
var imageName_2 : String = xmlData_xml [0].attributes.image_sub
but it does not work even tough trace(image_sub) outputs sub_2

but if I explicitly say this
var imageName_2 : String = xmlData_xml [0].attributes.sub_2
it works

Mad !!!

Load Another XML Attribute Help
Anyone know why the attribute "id" might not be displaying when compiled?

This is what the AS looks like, where "name" and "href" are working, but not "id".

for (var j = 0; j<shortcut.childNodes.length; j++)submenu_array.push({caption:shortcut.childNodes[j].attributes.name, id:shortcut.childNodes[j].attributes.id, href:shortcut.childNodes[j].attributes.href});
}
menu_array.push({caption:shortcut.attributes['name'], id:shortcut.attributes['id'], href:shortcut.attributes['href'], subnav_array:submenu_array});
}

this is what the XML looks like:

<navigation>
<menu name="Busta Rhymes" id="hwdiov" href="How We Do It.mp3">
<submenu name="How We Do It" id="hwdiov" href="How We Do It.mp3" />
</menu>
</navigation>

XML Tag Attribute Not Available After Update.
Hi everyone!

Having some strange behaviour from an XML manager class I'm working on.

I have an XML file that contains information about media files and this class allows the easy adding, deleting and editing this info.

There is a problem when adding a node to the XML (a node representing a media file, containing all its properties in nested sub-nodes). The node, when added is given an attribute 'id' with a number. Once this is done, I am able to loop through the XML document to trace all the nodes including the new node with its ID, but I can't actually access the 'attributes.id' property of that node straight away - I'm getting 'undefined' even though it's definitely there.

Has anybody experienced this and does anyone know a way around?

Thanks!
Tim

E4X Attribute Names
lets say we have an XML object, x which holds the following xml:
<data age='5' name='bobo'>

getting the attribute values is easy:


Code:
for each ( var s:String in x.attributes() ){

trace( s ); // outputs '5' and then 'bobo'

}
but how do I get the attribute names (age, name)?
when I invoke the attributes() method it returns an XMLList
with indices.

Xml Attribute Retrieval
im lost here, i would like to ask you guys if you have any idea on how will i be able to retrive an attribute in my xml file everytime i would press a button.

example xml:

<menu>
<label name="hello" id="1"/>
</menu>

---- i want to just display the attribute "id" in a dynamic textbox everytime i press a button in my flash movie.

thanks for the tips in advance.

Changing Attribute Value E4X
Hi,

I am loading an xml file into flash and trying to change the attribute values within flash.

I can change one value like this:

Code:
extraXML.item[3].@newID=String(300);
This changes the attribute value of the 'id' attribute in the fourth node just fine into '300'.

But when I try to do this for all the nodes, like:

Code:
for(var n:uint=0; n <extraXML.item.length(); n++){
trace(extraXML.item[n].@id)//traces the values correctly
extraXML.item[n].@id=String(n);
// or: extraXML.item[n].@id=n;

}
the values are being changed but come out messily organized, randomly as it seems. The idea is that I would like to number the id's from 0 to extraXML.item.length().

Must be missing something!

Thanks,

Jerryj.

XML Attribute Matching
So I'm trying to do a quiz, where each question is categorized, so I can pull out a list of the questions of one category, like so:

ActionScript Code:
var questions:XML =
    <questionList>
        <question text="Question1" cat1="true" ></question>
        <question text="Question2" cat2="true" ></question>
        <question text="Question3" cat1="true" cat2="true" ></question>
    </questionList>;
trace(questions.question.(@cat1=="true").@text);

And this gives the error "Error #1065: Variable @cat1 is not defined."

So I could solve this by using

ActionScript Code:
var questions:XML =
    <questionList>
        <question text="Question1" cat1="true" cat2="false" ></question>
        <question text="Question2" cat1="false" cat2="true" ></question>
        <question text="Question3" cat1="true" cat2="true" ></question>
    </questionList>;
But that makes the maintenance of the XML file annoying; if I ever add a category, I'll need to add it to every single question.

I tried this:

ActionScript Code:
var questions:XML =
    <questionList>
        <question text="Question1" ><cat1 text="cat1" /></question>
        <question text="Question2" ><cat2 text="cat2" /></question>
        <question text="Question3" ><cat1 text="cat1" /><cat2 text="cat2"/></question>
    </questionList>;
trace(questions..cat1.parent.@text);
But it outputs nothing, so I don't think .parent is working right.

I don't want to just use

ActionScript Code:
<question text="Question1" cat="1" >
because then I won't be able to put one question in two categories, like I did with question3.

So what's a good way to handle this?

Cannot Read XML With Val Attribute
Hi i have been making rounds with this and cannot figure it out, im am really new to flash and want to show some data from a weather station xml in a SWF.

this is the xml I CANNOT MAKE TO BE READ IN FLASH, is all says undefined... i dont know how to access it...

<conds>
<IGUATEMA3>
<id val="IGUATEMA3"></id>
<lat val="14.60016537"></lat>
<lon val="-90.52138519"></lon>
<adm1 val="Guatemala"></adm1>
<adm2 val="GUATEMALA"></adm2>
<country val="Guatemala"></country>
<neighborhood val="Zona 9"></neighborhood>
<dateutc val="2008-09-29 01:28:02"></dateutc>
<winddir val="338"></winddir>
<rainin val="0.00"></rainin>
<dailyrainin val="0.00"></dailyrainin>
<baromin val="30.11"></baromin>
<dewptf val="61.9"></dewptf>
<weather val=""></weather>
<clouds val=""></clouds>
<windchillf val="-999"></windchillf>
<heatindexf val="63"></heatindexf>
<softwaretype val="WUHU216HW"></softwaretype>
</IGUATEMA3>
</conds>


the diference is the val... since before i was able to show that data to dynamic text objects in flash via this

destino_txt.text = obj_xml.firstChild.childNodes[1].firstChild.nodeValue

but the xml is different...

<current_observation>
<station_id>IGUATEMA3</station_id>
<station_type>LaCrosse</station_type>
<temp_f>62.8</temp_f>
<temp_c>17.1</temp_c>
...
</current_observation>

thanks

Extracting An Attribute's Name (not It's Value)
Is there a way to extract an attribute's name (not value) from an XML doc?
For example, I'd like to assign the attribute name "extra" to the variable "myAttribute":

var theXML:XML = <tag extra="Middle name = Christopher">He's a little monster</tag>;

var myAttribute:String = ???

Thank you.

XML Attribute And Array
Hello again :S

I need to create an array like this:

Code:
var colors:Array = ["red","blue","green"]
But I have to create it using XML data that flash client received.

Code:
<colourlist colours="red|blue|green" />
I tried using this but doesn't work:

Code:
var colors:Array = new Array();
colors.push(xml.attribute("colours").split("|"));
have I done something wrong?

Thanks in advance.

Xml Attribute To AS Function. How?
I'm working with an xml expanding window, and can't figure out how to get actionscript to run a function onRelease (I can make it getURL, but not call a function). The script in the source flash, reading the attribute location, reads:

_root.gotoFunction(this.page)

How do I rewrite this?

XML Attribute In List Box
Hi.

I am having a little probelm getting the value of an xml attribute to appear in a list box. When using the code below, the trace command outputs the correct information, however I cant get the list box to display this information. Can anyone suggest where I am going wrong.

Thanks

Barry.








Attach Code

ACTIONSCRIPT on frame 1 in the Actions layer
----------------------------------------------------------

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoaded);

// create a new XML object named "xml".
var xml:XML;

// create the function "onLoaded".
function onLoaded(e:Event):void
{
xml = new XML(e.target.data);
var il:XMLList = xml.navigation.main_navigation;

for(var i:uint = 0; i < il.length(); i++)
{
trace(il[i].attribute("label"));
trace(il[i].attribute("url"));

lb.addItem(il[i].attribute("label"));
}
}

// load the xml file.
loader.load(new URLRequest("xml/navigation.xml"));


XML:
-----------------------------------------------------------

<?xml version 1.0 encoding="UTF-8" ?>

<website>

<navigation>

<main_navigation label="Home" url="index.html"/>

<main_navigation label="Portfolio" url="portfolio.htm">
<sub_navigation label="Website Design" url="website_design.htm"/>
<sub_navigation label="Flash" url="flash.htm"/>
<sub_navigation label="AIR Applications" url="air_applications.htm"/>
<sub_navigation label="Print Design" url="print_design.htm"/>
</main_navigation>

<main_navigation label="Contact" url="contact.htm"/>

</navigation>

</website>

Copyright © 2005-08 www.BigResource.com, All rights reserved