[help] Flash xml check

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…

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

meaning before loading the xml or after loading it ?

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?

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;
}

}

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);
}
};

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…

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”?

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=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.

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…

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

Can you post your code in a working fla ? perhaps

Here we go…

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

[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]

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…

always welcome :slight_smile: