PDA

View Full Version : [php] Can't get variables into flash



thorseye
April 4th, 2004, 06:25 PM
Ok, I've tried and tried for a very long time now. I've searched the forums and all threads are saying the same, but I can't get it to work. So maybe you could help me a little bit.

I've got a menu with a submenu, and I want to know which submenu the user last clicked. So I've got this script on the submenubuttons:


on (release) {
getURL("index.php?plats=1", "_self");
}
on (release) {
getURL("index.php?plats=2", "_self");
}

where the variable "plats" is a number.

I can easily write this number on my php-page. It clearly says: &plats=1 or &plats=2 depending on what button I pressed.

But now to the thing. I can't get flash to understand that I'm trying to load this variable into flash again to set some _y-values on a MC.

This is the script I'm using on the MC:


onClipEvent(load) {
loadVariables("index.php", 0, "GET");
if (_root.plats == 1 || _root.plats == null) _root.newpos = 155;
else if (_root.plats == 2) _root.newpos = 130;
else if (_root.plats == 3) _root.newpos = 104;
else if (_root.plats == 4) _root.newpos = 77;
}


But as I said, I can't get flash to understand what value the variable "plats" has. So please. Help me...

Jubba
April 4th, 2004, 09:58 PM
change your flash code into:



myLV = new LoadVars();
myLV.onLoad = function(success){
if(success){
if (_root.plats == 1 || _root.plats == null) _root.newpos = 155;
else if (_root.plats == 2) _root.newpos = 130;
else if (_root.plats == 3) _root.newpos = 104;
else if (_root.plats == 4) _root.newpos = 77;
}else{
trace("Failure loading...");
}
}
myLV.load("index.php", this, "get");


Whenever possible use loadVars. Much more powerful. gives your more options for dealing with your variables. :0

thorseye
April 5th, 2004, 05:26 AM
Hmm... Well the phrase "Failure loading..." is never showed so I guess he loads something. Is there some way to see everything that is loaded? Writing out all variables in a dynamic text-field or something like that.
By the way.. If you use

myLV.load("index.php", this, "get");
wouldn't it be this.plats instead of _root.plats? Well, that didn't work either...

Could it be something wrong with my php-page? Must the only content on the page be the variables, or could you have a lot of other stuff on the page aswell?

Maybe you could take a look on the page and understand what i'm talking about.
http://thorseye.mine.nu/tonar/index.php
It's in Swedish, but it really doesn't matter.. I think that the menu should be quite easy to understand anyway.

kill.robot.kill
April 5th, 2004, 02:06 PM
add this to your code:


myLV = new LoadVars();
myLV.onLoad = function(success){
if(success){
trace ("connection!"); //-------here
if (_root.plats == 1 || _root.plats == null) _root.newpos = 155;
else if (_root.plats == 2) _root.newpos = 130;
else if (_root.plats == 3) _root.newpos = 104;
else if (_root.plats == 4) _root.newpos = 77;
trace ("newpos = "+_root.newpos); //------- and here
}else{
trace("Failure loading...");
}
}
myLV.load("index.php", this, "get");