Skip to main content
sbryner
Inspiring
November 14, 2006
Question

for .... for.... if loop

  • November 14, 2006
  • 19 replies
  • 1831 views
hello,

I'm trying to search an XML file checking the childNodes of said file.
The problem is I have a function that looks like this:

going into the if statement the to variables I want to check to see if they are equal ARE EQUAL
but it does not go pass the if portion of the function

Why?

please help.
This topic has been closed for replies.

19 replies

kglad
Community Expert
Community Expert
November 22, 2006
you're welcome.

p.s. it's easy to change a prototype method into a function. that function can probably be easily adapted to working on 2-d arrays like myResults.

if you want to try going that route, post the code to your Array.prototype method.
sbryner
sbrynerAuthor
Inspiring
November 22, 2006
Thanks again,

I used it (pre XML) like this:
my "search.swf" loads into a "main.swf" and the result loads "searchResults.swf " into the "main.swf" onRelease...

searchCriteria in my code = comboBox.value
searchBy = a string // set when "onRelease" was executed to tell what element in the array to look for.

I hope you can picture what I'm doing here.
At least that was before XML was introduced into my life.

Now I'm trying to get the searched value from my comboBox.value, search the XML file for the value
once found it loads it into the mc's of my returnSearch.swf.

anyway you probably don't need to know all that but here is my prototype array and how it is used pre XML

sbryner
sbrynerAuthor
Inspiring
November 22, 2006
Thanks Kglad for all the help.

I've been working on my own little project for awhile and it went from searching an AS Array and placing the elements into seperate MC's which inside them load all the elements for each "valueToSearchFor" into dynamic text boxes and image paths load into mc's to display pictures.

I'm back on track now that you've helped me. I've got a ways to go. I have a prototype I used before with the AS associates array but now I don't think I can use it. I'm going to try another avenue instead of the Array.prototype for this.

I'm going to try using :

loadName= myResults[ i ] [ 0 ];
loadComment = myResults[ i ] [ 1 ];

like I used the Array.prototype to create this before:

email_txt.text = searchResult [ i ].email;

if you see an automatic problem with this please let me know.
else, I'm going to venture back into the relm of "self searching" to
continue my little project.

I really appreciate your help and time... Man, couldn't have done it without ya.
I've been working on this problem for 2 months now.

Thanks a bunch, and I'm sure...wait, I KNOW, I'll have more questions in the future I hope you will help with.

thanks for everything.
sbryner
sbrynerAuthor
Inspiring
November 21, 2006
THE CODE WORKS. I was using the xml file to just to test this project.

One more question. I've been reading about searching XML on Kirupa.com
and I want to add the nodeValue of my search into the myResults Array.
I thought everytime I entered into the if statment I could use:

myResults.push(this(nodesToLookIn[ i ].childNodes)); // I know this code is wrong but something like it is what I'm trying to do.

this would add all the childNodes for that person into an array (myResults) as elements. My ultimate goal is something like this with the myResult:

myResult = [{myName:"p", comments: "thats my ol man";}
{myName:"p", comments:"hey man"}];

or something along those lines so I could load each item from the myResults array into text fields and image names into mc's.

Am I out there on this idea or is it possible? If so, am I close to doing this?
kglad
Community Expert
Community Expert
November 22, 2006
here's your code with some comments so you might better see what your accessing:

sbryner
sbrynerAuthor
Inspiring
November 20, 2006
I'm still struggling with this Object and String problem

I'm getting the myNodes = Object & valueToSearchFor = String

I'm wanting them to be the same correct so I can check for equality?
kglad
Community Expert
Community Expert
November 21, 2006
that's not a well-formed xml file. and second, you need to check the nodeValue of myNode against valueToSearchFor:

sbryner
sbrynerAuthor
Inspiring
November 17, 2006
Just don't give up on me. I was once told by another member: kglad > all
so you helping me feels like one of the greats helping me.


I've tried the last three codes posted "tl=this" removing the "tl=this" and using this plus the last "if(nodesToLookIn[ i ].childNodes[ j ] [valueToSearchFor] == myNode)"

thanks for clarifying a little more for me in your last reply.
kglad
Community Expert
Community Expert
November 18, 2006
well, in my last reply i started explaining why the situation you were describing couldn't happen when i typed myself towards, what i think is, the solution.

try:

sbryner
sbrynerAuthor
Inspiring
November 20, 2006
Hi, Neither code worked. I'm posting all my info so you may see something I'm missing elsewhere.

The only other thing is two components on the stage, a button component on the stage and a
comboBox component .

The comboBox has a value of "p" and a data value of "p".
This is just so you may see a step I've not taken.

can you see anthing I must do first other than the code posted?

sky

Here is my xml file:

<?xml version="1.0" ?>
<family>
<person>
<myname>p</myname>
<comments>That's my ol' man!</comments>
</person>
<person>
<myname>Silly Sally</myname>
<comments>She's so funny</comments>
</family>



kglad
Community Expert
Community Expert
November 17, 2006
an object needs to already exist as a child of some other object (usually a timeline, but not necessarily). you can then use the fact that children of objects are stored, by flash, in an array of the object.

myNode is an array, correct? and when you trace(myNode) you see one value because myNode is an array containing one element. maybe you should be testing myNode[0] against valueToSearchFor. lol, i'm bound to get it sooner or later.
sbryner
sbrynerAuthor
Inspiring
November 16, 2006
also... to declare the variable an object you only need to add brackets? that's it?

[ stringIsNowAnObject ] ?
sbryner
sbrynerAuthor
Inspiring
November 16, 2006
still nada!

could it be something to do with the component value or heck I don't get it.
sbryner
sbrynerAuthor
Inspiring
November 16, 2006
tried that before I replied. no go on that either
kglad
Community Expert
Community Expert
November 16, 2006
lol, ok. how about:

sbryner
sbrynerAuthor
Inspiring
November 16, 2006
ok... now I'm lost.. I've looked at kirupa.com and google search to find out how to create:

"bracket notation to resolve the string to an object "

can you give me an example I can "pick apart/study" line by line so I can understand this more (I'd like to be able to truely understand it not just use it for this project) or send a site that I can go to so I know exactly what I'm trying to do?

I know just changing the "new String" to "new Object" won't work in the code posted above.

Hope I'm not frustrating you.
kglad
Community Expert
Community Expert
November 16, 2006
try:

sbryner
sbrynerAuthor
Inspiring
November 16, 2006
Still doesn't trace inside the if statement?

I can trace to the line above the if statment but does not go inside the statement...
do you know why this might be?