View Full Version : Action Script 2.0 Help needed!
eliz_sky
10-09-2007, 06:11 AM
Hi. Currently, i'm facing some action scripts problem. I need to create a flash which get the external/dynamic data from .txt, after getting data value and gotoAndPlay another scene. Below script seemed not workable.. Coz can't get the right variable and keep playing the wrong scene. Any flash expert willing to help me? :)
My text file content is :
point= 8000
Code is :
var myData= new LoadVars();
myData.load("details.txt");
totalpoint.text = this.point;
myData.onLoad = function(totalpoint:Number) {
if((totalpoint > 8000) && (totalpoint < 10000)) {
gotoAndPlay("Scene 5", 1);
} else if ((totalpoint > 7999) && (totalpoint < 6000)) {
gotoAndPlay("Scene 4", 1);
} else if ((totalpoint > 5999) && (totalpoint < 3000)) {
gotoAndPlay("Scene 3", 1);
} else {
gotoAndPlay("Scene 2", 1);
}
}
Thank you very much.:D
patmanbofh
10-15-2007, 02:29 PM
Hi there.. a couple of issues with your code. firstly your mydata.onload function. The totalpoint parameter is returning a boolean value indicating successful/failure for the load event not a number. So I presume you will always default to gotoandplay("scene 2", 1);
Your if statements appear to be mutually exclusive i.e.
Assuming a point value of 8000
if(totalpoint>8000 && totalpoint<10000) will fail as 8000 is not greater than 8000.
if(totalpoint>7999 && totalpoint <6000) will fail as 8000 cannot be greater than 7999 and less than 6000. The same applies to the other if statements, the if conditionals will always return false
changing your onload function to the something similar should help resolve the issues
myData.onLoad = function(success:Boolean)
{
var ipointval:Number;
//onload function returns true for success
if (success) {
//set up the point value from the details.txt file
ipointVal = this.point;
if((ipointVal >= 8000) && (ipointVal <= 10000))
{
trace("scene 5 selected");
gotoAndPlay("Scene 5", 1);
}
else if ((ipointVal >= 6000) && (ipointVal < 8000))
{
trace("scene 4 selected");
gotoAndPlay("Scene 4", 1);
}
else if ((ipointVal >= 3000) && (ipointVal < 6000))
{
trace("scene 3 selected");
gotoAndPlay("Scene 3", 1);
}
else
{
trace("scene 2 selected");
gotoAndPlay("Scene 2", 1);
}
//if function returns false for boolean success
}
else
{
trace("Error loading/parsing LoadVars.");
}
}
Hope this helps!!
BLiZZaRD
10-16-2007, 06:07 PM
Another point to look at, which was corrected in the above post but not mentioned, you need the old "double variables" inside your If statements.
so if ((totalpoint > 8000) && (totalpoint < 10000)) {
becomes if((totalpoint >= 8000) && (totalpoint <= 10000)) {
:)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.