Everything I’ve tried with this script has ended with no positive result, this was developed in flash 9, but attempting to publish in flash 10 since its no longer working after updating flash. I have also upgraded from CS3 to CS5 recently also if that makes any difference. Well, here’s the code:
source file is here:
http://test.reaper-productions.com/protect.fla
AS3 code:
stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; stage.showDefaultContextMenu = false; //path to the php file on your server var phpPath:String = "login.php"; //make password text field (when you type the characters will be like "******") pass.displayAsPassword = true; login.addEventListener(MouseEvent.MOUSE_DOWN, loginDown); function loginDown(e:MouseEvent):void{ //check to see if something in both the user and pass text fields if (user.text != "" && pass.text != "") { sendLoadData(); }else{ trace("Please fill in both username and password"); } } stop(); function sendLoadData():void { var dataRequest:URLRequest = new URLRequest(phpPath); dataRequest.method = URLRequestMethod.POST; // define the custom parameters that will be sent to the .php file var params:URLVariables = new URLVariables(); params.user = user.text; params.pass = pass.text; dataRequest.data = params; var urlLoader:URLLoader = new URLLoader(); urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES; urlLoader.addEventListener(Event.COMPLETE, urlLoaderComplete); try { urlLoader.load(dataRequest); } catch (event:Error) { trace("Incorrect PHP file path."); } } function urlLoaderComplete(event:Event):void { // once all the data has been sent and we'll check for a message sent // from the php file to tell us if the operation has ended with success or not errorHandler(event.target.data.secure_response); } function errorHandler(message:Number):void { // check the message that was sent back from the php file //trace(message) if (message == 1) { gotoAndStop(2); } else { trace("Wrong Username or Password"); } }
PHP code:
<?php //Your set username and password $username = "test"; $password = "test1"; //Variables received from ActionScript $user=$_POST['user']; $pass=$_POST['pass']; //Chack them against each other if ($user == $username && $pass == $password){ print "secure_response=1"; }else{ print "secure_response=2"; } ?>
Error I’m recieving is:
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()
and if I change the:
urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
to:
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
The error I receive is:
ReferenceError: Error #1069: Property secure_response not found on String and there is no default value.
at passwordprotected_fla::MainTimeline/urlLoaderComplete()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
I truly need some help here