# \[help\] Flash xml check

**URL:** <https://forum.kirupa.com/t/help-flash-xml-check/261520>\
**Category:** flash\
**Created:** [May 28, 2008, 1:59pm UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520 "2008-05-28T13:59:52Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![korpela2](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@korpela2](https://forum.kirupa.com/u/korpela2)\
**Post date:** [May 28, 2008, 1:59pm UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/1 "2008-05-28T13:59:52Z")

</div>

Hi all,

I wonder is there a way to check through Flash if a XML file contains a certain piece of data. (like a password check)

I know you would usually use a MySQL database for this, but I’m wondering is there a simple way of doing the same thing with XML?

Any help would be much appreciated…

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [May 28, 2008, 6:11pm UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/2 "2008-05-28T18:11:26Z")

</div>

how do you want to do it… on server side or on client side ?

meaning before loading the xml or after loading it ?

---

<div class="post-metadata">

**Author:** ![korpela2](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@korpela2](https://forum.kirupa.com/u/korpela2)\
**Post date:** [May 29, 2008, 8:20am UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/3 "2008-05-29T08:20:14Z")

</div>

After the XML is loaded [I think].

Ill run down how my version is running at the moment.

1. Swf opens and loads a XML file
2. User enters a serial into a dymanic password text box. [actionscript determines if it’s correct or incorrect]
3. According to this password, a function draws specific data from the XML file into dynamic text-boxes e.g. \<name\>,\<company\>,\<serial\>, etc.

However this results in creating numerous lines of code (400+) for each seperate password e.g

if (\_root.Password == “12345”) {

Hence,  
It would be better if the code was able to check if the serial, that was entered, existed in the XML file and then loaded the correct data corresponding to that serial.

This would save me writing hundreds of lines of actionscript code, as well as changing the code when the XML is edited or added to.

Do you think this is possible?

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [May 29, 2008, 9:44am UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/4 "2008-05-29T09:44:44Z")

</div>

It would be better if the code was able to check if the serial, that was entered, existed in the XML file and then loaded the correct data corresponding to that serial.

* * *

Checking password from xml will be pretty insecure though…

still… in your xml structure have nodes like this…

\<dataNode\>  
\<pass\>\</pass\>  
\<data\>\</data\>  
\</dataNode\>

then after loading the xml parse it and store the items in objects

for(var i=0;i\<xmldomlength;i++)  
{  
var obj=new Object();  
obj.pass=xml.firstChild.childNodes\*.childNode[0];  
obj.data=xml.firstChild.childNodes\*.childNode[1];

myarray.push(obj);  
}

// then later do  
for(var i=0;i\<myarray.length;i++)  
{  
var pass=myarray\*.pass;  
if(pass==textbox.text)  
{  
// hooray  
var datatoshow=myarray\*.data;  
}

}

---

<div class="post-metadata">

**Author:** ![korpela2](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@korpela2](https://forum.kirupa.com/u/korpela2)\
**Post date:** [May 29, 2008, 10:39am UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/5 "2008-05-29T10:39:31Z")

</div>

Hey man,

That’s seems like the way to go. I’m just a bit confused at where to place the code. This is my code so far:

* * *

FRAME 1

//loads XML  
tuteInfo\_xml = new XML();  
tuteInfo\_xml.ignoreWhite = true;  
tuteInfo\_xml.onLoad = function(success) {  
if (success) {  
trace (‘success’);  
}  
};  
tuteInfo\_xml.load(‘contacts.xml’);

FRAME 2

////check to see if the password entered is correct and load XML data  
////nextcheck is attached to a button

\_global.nextcheck = function() {  
if (\_root.Password == “11111”) {

gotoAndPlay(“termsConditions”);  
serial\_txt = (tuteInfo\_xml.firstChild.childNodes[0].firstChild.firstChild);  
serial\_txt2 = (tuteInfo\_xml.firstChild.childNodes[0].firstChild.firstChild);  
FirstName = (tuteInfo\_xml.firstChild.childNodes[0].childNodes[1].firstChild);  
Email = (tuteInfo\_xml.firstChild.childNodes[0].childNodes[2].firstChild);  
mySignal = (tuteInfo\_xml.firstChild.childNodes[0].childNodes[3].firstChild.nodeValue);  
mydt = (tuteInfo\_xml.firstChild.childNodes[0].childNodes[4].firstChild.nodeValue);  
}  
};

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [May 29, 2008, 4:59pm UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/6 "2008-05-29T16:59:40Z")

</div>

why are you using this \_root.Password == “11111”

you want it to be intelligent checking right? so see the code posted earlier…

never hard code values… like fixes values…

---

<div class="post-metadata">

**Author:** ![korpela2](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@korpela2](https://forum.kirupa.com/u/korpela2)\
**Post date:** [May 30, 2008, 9:02am UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/7 "2008-05-30T09:02:00Z")

</div>

why are you using this \_root.Password == “11111”

you want it to be intelligent checking right? so see the code posted earlier…

never hard code values… like fixes values…

* * *

That was my previous code I used in the last message.

I’m running into some difficulties placing your new code into my fla.

This is what I have done so far:

FRAME 1

tuteInfo\_xml = new XML();  
tuteInfo\_xml.ignoreWhite = true;  
tuteInfo\_xml.onLoad = function(success) {  
if (success) {

```
                                              trace ('success');
                                              }
                                              };

```

tuteInfo\_xml.load(‘contacts2.xml’);

for(var i=0;i\<xmldomlength;i++)  
{  
var obj=new Object();  
obj.serial=tuteInfo\_xml.firstChild.childNodes\*.childNode[0];  
obj.name=tuteInfo\_xml.firstChild.childNodes\*.childNode[1];  
obj.company=tuteInfo\_xml.firstChild.childNodes\*.childNode[2];  
obj.signal=tuteInfo\_xml.firstChild.childNodes\*.childNode[3];  
obj.dt=tuteInfo\_xml.firstChild.childNodes\*.childNode[4];

myarray.push(obj);  
}

FRAME 2

\_global.nextcheck = function() {

for(var i=0;i\<myarray.length;i++)  
{  
var pass=myarray\*.serial;

```
          if(pass==Password.text) {
                      var FirstName=myarray*.name;
                      var Email=myarray*.company;
                      var mySignal=myarray*.signal;
                      var mydt=myarray*.dt;
                      gotoAndPlay(3);
          } else {

```

\_root.Guide = “Invalid Number Entered…please try again”;  
stop();  
}  
}  
};

However it does not respond to this. Could it have something to do with the “xmldomlength”?

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [May 30, 2008, 6:00pm UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/8 "2008-05-30T18:00:08Z")

</div>

What do you mean by… “it does not respond?”

trace myarray and myarray.length in the second frame to see what you get…  
if you get undefined… its probably a scope problem.

declare myarray as myarray=[]; in the first line of the first frame. this makes it global.

---

<div class="post-metadata">

**Author:** ![korpela2](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@korpela2](https://forum.kirupa.com/u/korpela2)\
**Post date:** [June 3, 2008, 9:03am UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/9 "2008-06-03T09:03:45Z")

</div>

[quote=sparkdemon;2333740]What do you mean by… “it does not respond?”

trace myarray and myarray.length in the second frame to see what you get…  
if you get undefined… its probably a scope problem.

declare myarray as myarray=[]; in the first line of the first frame. this makes it global.[/quote]

* * *

when I trace “myarray” nothing is displayed in the output window and after tracing “myarray.lenght” a “0” is displayed.

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [June 3, 2008, 1:01pm UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/10 "2008-06-03T13:01:29Z")

</div>

Ensure that you go to the second frame only after… you have completed

for(var i=0;i\<xmldomlength;i++)  
{  
var obj=new Object();  
obj.serial=tuteInfo\_xml.firstChild.childNodes\*.childNode[0];  
obj.name=tuteInfo\_xml.firstChild.childNodes\*.childNode[1];  
obj.company=tuteInfo\_xml.firstChild.childNodes\*.childNode[2];  
obj.signal=tuteInfo\_xml.firstChild.childNodes\*.childNode[3];  
obj.dt=tuteInfo\_xml.firstChild.childNodes\*.childNode[4];

myarray.push(obj);  
}

this code… not before this…

---

<div class="post-metadata">

**Author:** ![korpela2](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@korpela2](https://forum.kirupa.com/u/korpela2)\
**Post date:** [June 3, 2008, 1:45pm UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/11 "2008-06-03T13:45:23Z")

</div>

yea dude, the trace is still coming up with undefined and 0 for myarray and my array.length.

Here is my code so far. You might see something wrong with it:

**FRAME 1**

myarray = [];

tuteInfo\_xml = new XML();  
tuteInfo\_xml.ignoreWhite = true;  
tuteInfo\_xml.onLoad = function(success) {  
if (success) {

```
    var players_xml = tuteInfo_xml.firstChild;
    var serials_xml = players_xml.childNodes;
    for (var i=0; i&lt;serials_xml.length; i++){
    currSerials = serials_xml*;

    var obj=new Object();
    obj.serial = currSerials.childNodes[0].firstChild;
    obj.names = currSerials.childNodes[1].firstChild;
    obj.company = currSerials.childNodes[2].firstChild;
    obj.signal = currSerials.childNodes[3].firstChild;
    obj.dt = currSerials.childNodes[4].firstChild;
    
    myarray.push(obj);
    }
  } else {
      trace('Error loading playlist.');
  }

```

}  
tuteInfo\_xml.load(‘contacts.xml’);

**FRAME 2**

stop();

\_global.nextcheck = function() {  
for(var i=0;i\<myarray.length;i++){  
var serial = myarray\*.serial;

```
if(serial==Password.text) {
var FirstName = myarray*.name;
var Email = myarray*.company;
var mySignal = myarray*.signal;
var mydt = myarray*.dt;
gotoAndPlay(3);

} else {
_root.Guide = "Invalid Number Entered...please try again";
stop();

```

}  
}  
};

////////this is then executed by a button

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [June 3, 2008, 1:54pm UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/12 "2008-06-03T13:54:04Z")

</div>

Can you post your code in a working fla ? perhaps

---

<div class="post-metadata">

**Author:** ![korpela2](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@korpela2](https://forum.kirupa.com/u/korpela2)\
**Post date:** [June 3, 2008, 2:05pm UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/13 "2008-06-03T14:05:58Z")

</div>

> [@sparkdemon;2335522](#):
>
> Can you post your code in a working fla ? perhaps

Here we go…

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [June 3, 2008, 2:33pm UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/14 "2008-06-03T14:33:38Z")

</div>

check it out… problems… that were are pointed out in the file as comments  
[http://www.4shared.com/file/49964996/5075df90/testfile.html](http://www.4shared.com/file/49964996/5075df90/testfile.html)

---

<div class="post-metadata">

**Author:** ![korpela2](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@korpela2](https://forum.kirupa.com/u/korpela2)\
**Post date:** [June 3, 2008, 2:48pm UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/15 "2008-06-03T14:48:06Z")

</div>

[quote=sparkdemon;2335554]check it out… problems… that were are pointed out in the file as comments  
[http://www.4shared.com/file/49964996/5075df90/testfile.html[/quote]](http://www.4shared.com/file/49964996/5075df90/testfile.html%5B/quote%5D)

wow, nice one! Thanks, works perfectly.

I’ll insert it into the original project and see if it works. Should be fine though.

Thanks a million again for your help and persistency…

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [June 3, 2008, 2:52pm UTC](https://forum.kirupa.com/t/help-flash-xml-check/261520/16 "2008-06-03T14:52:42Z")

</div>

always welcome 🙂
