Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unable to transfer control (if problem)

Status
Not open for further replies.

webmast

Programmer
Dec 21, 2001
57
0
0
IN
Hi i am trying to do a flash website which looks different at different time of the day, say morning, afternoons & nite.

I have an asp page which send me the value of 1/2/3. Now i load this value in flash, but I am unable to shift the control to the respective frame, I think my if statement is not working.

The code on the first frame is.
----------------------------------------------------

rand=Math.round(math.random()*100000);
loadVariables("timeval.asp?i="+rand,"");

if (chkval == 1) {
gotoAndPlay(5);
}
if (chkval == 2) {
gotoAndPlay(6);
}
if (chkval == 3) {
gotoAndPlay(7);
}

------------------------------------------------------

where chkval is the name of the variable on the asp file.
the value asp returns will be &chkval=1 / &chkval=2 / &chkval=3.

I had even tried assigning chkval to another variable, but nothing seems to work.

I am able to get the value, but the if statement is not working.

I am using FlashMX2004. Someone plz help me...

Thanx in advance...

Regards,
Tommcat
 
You are probably executing your logic before the variables have actually loaded so you aren't getting anything. Try using the loadVars object instead:

Code:
myLoadVars = new LoadVars();
myLoadVars.onLoad = function(success:Boolean) {
	if (success) {
                //evaluate chkval. chkval=1 is the same as case "1"
		switch (myLoadVars.chkval) {
		case "1" :
			gotoAndPlay(5);
			break;
		case "2" :
			gotoAndPlay(2);
			break;
		case "3" :
			gotoAndPlay(7);
			break;
		}
	}else{
		trace("The variables did not load");
	}
};

rand=Math.round(math.random()*100000);

//execute the loadVars object
myLoadVars.load("timeval.asp?i="+rand);

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
I'm not on MX2004, but aren't supposed to set the variable type on MX2004 prior to using it?

var chkval:Number = 0;

Then your if statements after loading the ASP variables?

Regards. Affiliate Program - Web Hosting - Web Design
After 25,000 posts, banned on FK, but proud not to have bowed down to them!
 
Hi pixl8r,

I tried ur code, but when the movie loads it directly goes to the 5th frame all times.

I think the focus doesnt go at all to the switch for checking...

Can u send me a simple file or locate me somewhere they have done this :(

Thanx in advance...

Tommcat
 
Hi oldnewbie,

I had tried to assign variables & values but it wasnt working either. Even if you can help me on Flash MX (2003) is also fine...

I have been breaking my head on this for long :(

Tommcat
 
Have you confirmed that you are getting the correct information from your asp file? Try tracing your variable.

Code:
myLoadVars = new LoadVars();
myLoadVars.onLoad = function(success:Boolean) {
    if (success) {
        [highlight]trace(myLoadVars.chkval);[/highlight]
                //evaluate chkval. chkval=1 is the same as case "1"
        switch (myLoadVars.chkval) {
        case "1" :
            gotoAndPlay(5);
            break;
        case "2" :
            gotoAndPlay(2);
            break;
        case "3" :
            gotoAndPlay(7);
            break;
        }
    }else{
        trace("The variables did not load");
    }
};

rand=Math.round(math.random()*100000);

//execute the loadVars object
myLoadVars.load("timeval.asp?i="+rand);

Wow JT that almost looked like you knew what you were doing!
 
Hi pixl8r,

I am unable to trace the variables as the value is from an asp file. When I change it to a txt file I do get the value traced.

I cant figure why it is not working...

When i pass the if action thru a button, it works, but on the first frame it doesnt :(
 
You can still trace the variables if they have correctly loaded from the asp file (if you can't trace it they didn't load). Just to make sure... the output of your asp page should be:

&chkval=1

(or 2 or 3)

Might be better if you can zip your files and post them. I can have a look if you like.

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Looks like I messed it up. Change the value for case "2" to be gotoAndPlay(6). I made it gotoAndPlay(2) (which is why it isn't working.

Otherwise it seems to be working fine for me. One problem might be that you have to pass the asp page through the web server for it to process. So it should be something like:

Code:
//execute the loadVars object
myLoadVars.load("[URL unfurl="true"]http://localhost/timeval.asp?i="+rand);[/URL]

Hope that gets you going!

Wow JT that almost looked like you knew what you were doing!
 
Hi pixl8r,

I got this working with some help, the code now looks like...

---------------------------------------------------

rand=Math.round(Math.random()*100000);

loadVariables("timeval.asp?i="+rand,"");

this.onEnterFrame = function(){
if(chkval){
if (chkval == 1) {
gotoAndStop(5);

}
if (chkval == 2) {
gotoAndStop(6);

}
if (chkval == 3) {
gotoAndStop(7);

}
delete this.onEnterFrame;
}
}


-------------------------------------------------

Now it is giving the desired output...

Thanks to you, your postings did help me out on way to finding the solution...

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top