Link to home
Start Free TrialLog in
Avatar of tflock
tflock

asked on

Flash Actionscript 3 CS4: Incorrect return value assigned to variable

I have a created a .as file that reads from an XML file and returns a boolean value from the initializer function if the value was found or not.  However, when I call the .as with my .fla file, it returns a "false" value regardless if the element was found in my XML file.  Can anyone assist?  I have attached all required files.
CompatibilityTester.zip
Avatar of blue-genie
blue-genie
Flag of South Africa image

the problem seems to be that you're running your check in mostCompatible in a for each loop, so while the value is set to true, it keeps looping so eventually returns you a false.

You could do a break as soon as a true value is returned.
Avatar of tflock
tflock

ASKER

Thanks for the response blue-genie,
However, I didn't think the returnMostCompatible value could return a false value, because it is set to false at the begining of the Initialize function then set it to true in my case statement.  The case statement is in another if that checks to see if the XML attribute value equals the passedType parameter, see below.
if (passedType==compatibilityElement.attributes())

At any rate, it would improve perfomance if I break out of the for each loop instead of checking ever node, but I'm not sure how to do that.  I tried adding a break after my Switch statement just before the closing if "}", but that didn't work.  Any other suggestions?
SOLUTION
Avatar of blue-genie
blue-genie
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can i write entire new code for ur solution or should i edit only..
Avatar of tflock

ASKER

Hi blue-genie,
I attempted to set a break after the for loop, but that didn't work either.  I traced the returnMostCompatible var and it shows true for me each time it goes through the loop.  I have no clue where it is being set to false.  I have attached my current .as file for review.  Not sure were or how to break out of the for loop.  Any help you can provide would be appreciated.

mostCompatible.as
Avatar of tflock

ASKER

vishalreddy57,
I would prefer you edit, but as I am a novice, I welcome any actionscript conventions in object oriented programming.  This was the only way I could get the file to run as a .as file.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tflock

ASKER

Vishalreddy57 thanks for your assistance.
 Your code is much cleaner, but I did get my code to run by calling the initialize function from the contructor in my .as file.  And putting return statement in switch statements in my  parse function to get it to stop the execution of the for each loop.