Im kind of new to this forum so I do my best…
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at flash.net::URLLoader/onComplete()
I’m not where error exactly the error happen so I post the whole thing.
As far I know bottom code that relate to send_loc.php works fine, get_loc.php is having a problem. The output from get_loc.php is
&x=400&y=375&o=1
import flash.net.*
import flash.events.Event;
////////
var leftKeyDown:Boolean=false;
var upKeyDown:Boolean=false;
var rightKeyDown:Boolean=false;
var downKeyDown:Boolean=false;
//the main character's speed
var mainSpeed:Number=7;
//whether or not the main guy is jumping
var mainJumping:Boolean=false;
//how quickly should the jump start off
var jumpSpeedLimit:int=15;
//the current speed of the jump;
var jumpSpeed:Number=0;
//adding a listener to mcMain which will make it move
//based on the key strokes that are down
mcMain.addEventListener(Event.ENTER_FRAME, moveChar);
///for enterframe
///
//player2 position polling
//string of the url
var get_locURL:String ="http://xxxxxxxx.net/toh/get_loc.php";
//netcom for the url nocache and urlstring attached
var get_mcMain2:netcom = new netcom(get_locURL);
//request the url and request method
var urlRequest0:URLRequest = new URLRequest(get_locURL);
urlRequest0.method=URLRequestMethod.GET;
//get_locLoader
//make a new url loader
var get_locLoader:URLLoader = new URLLoader();
//set loader format
get_locLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
//load the url request
get_locLoader.load(urlRequest0);
//problem happened here below
get_locLoader.addEventListener(Event.COMPLETE, handleDataSource);
function handleDataSource():void {
//make vars and put them into mcMain2
var get_loc:URLVariables = new URLVariables();
//get_loc
get_loc.data = urlRequest0;
this.mcMain2.x=(get_loc.x);
this.mcMain2.y=(get_loc.y);
this.mcMain2.o=(get_loc.o);
trace(urlRequest0.data);
}
//trace(get_loc.x);
////
function moveChar(event:Event):void {
//trace(charx.datax);
//if certain keys are down then move the character
if (leftKeyDown) {
mcMain.x-=mainSpeed;
}
if (rightKeyDown) {
mcMain.x+=mainSpeed;
}
if (upKeyDown||mainJumping) {
mainJump();
}
}
//listening for the keystrokes
//this listener will listen for down keystrokes
stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
function checkKeysDown(event:KeyboardEvent):void {
//making the booleans true based on the keycode
//WASD Keys or arrow keys
if (event.keyCode==37||event.keyCode==65) {
leftKeyDown=true;
this.mcMain.scaleX=1;
this.mcMain.o=1;
}
if (event.keyCode==38||event.keyCode==87) {
upKeyDown=true;
}
if (event.keyCode==39||event.keyCode==68) {
rightKeyDown=true;
this.mcMain.scaleX=-1;
this.mcMain.o=2;
}
if (event.keyCode==40||event.keyCode==83) {
downKeyDown=true;
}
var send_loc:URLVariables = new URLVariables();
send_loc.x=(this.mcMain.x);
send_loc.y=(this.mcMain.y);
send_loc.o=(this.mcMain.o);
var send_locURL:String ="http://xxxxxxxxx/toh/send_loc.php";
var urlRequest:URLRequest = new URLRequest(send_locURL);
urlRequest.method=URLRequestMethod.POST;
urlRequest.data = send_loc;
var send_locLoader:URLLoader = new URLLoader();
send_locLoader.load(urlRequest);
/////////////
///////////
}
//this listener will listen for keys being released
stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
function checkKeysUp(event:KeyboardEvent):void {
//making the booleans false based on the keycode
if (event.keyCode==37||event.keyCode==65) {
leftKeyDown=false;
}
if (event.keyCode==38||event.keyCode==87) {
upKeyDown=false;
}
if (event.keyCode==39||event.keyCode==68) {
rightKeyDown=false;
}
if (event.keyCode==40||event.keyCode==83) {
downKeyDown=false;
}
}
//jumping function
function mainJump():void {
//if main isn't already jumping
if (! mainJumping) {
//then start jumping
mainJumping=true;
jumpSpeed=jumpSpeedLimit*-1;
mcMain.y+=jumpSpeed;
} else {
//then continue jumping if already in the air
//crazy math that I won't explain
if (jumpSpeed<0) {
jumpSpeed*=1-jumpSpeedLimit/200;
if (jumpSpeed>- jumpSpeedLimit/5) {
jumpSpeed*=-0.5;
}
}
if (jumpSpeed>0&&jumpSpeed<=jumpSpeedLimit) {
jumpSpeed*=1+jumpSpeedLimit/50;
}
mcMain.y+=jumpSpeed;
//if main hits the floor, then stop jumping
//of course, we'll change this once we create the level
if (mcMain.y>=stage.stageHeight-mcMain.height) {
mainJumping=false;
mcMain.y=stage.stageHeight-mcMain.height;
}
}
}
////
get_loc.php:
<?php
include "connect.php";
$get_loc = mysql_query("SELECT `x` , `y` , `o` FROM `char` WHERE `char_id` =2");
while ($row = mysql_fetch_array($get_loc, MYSQL_BOTH)) {
//set each row value to each var
$x=$row[x];
$y=$row[y];
$o=$row[o];
}
mysql_free_result($get_loc);
echo ("&x=".$x."&y=".$y."&o=".$o);
?>
send_loc.php:
<?php
include "connect.php";
$sendloc = "UPDATE `flashdb`.`char` SET `x` = '$_POST[x]',`y` = '$_POST[y]',`orientation` = '$_POST[o]' WHERE `char`.`char_id` = '1'";
mysql_query($sendloc);
?>