Hello,
A while ago Multiplayerfunplace version was started and is currently being re programmed with ActionScript 3.0.
We're going to start posting a "How to create a virtual world" series soon!
ActionScript 3 Tutorials
Free Flash ActionScript 3 tutorials, code snippets and code samples!
Tuesday, June 7, 2011
Friday, June 3, 2011
AS3 Code - Posting to web service / External Script
Hello,
Todays code snippet can be accessed using the below url:
Script Loader class: http://paste.hostingforoz.com/index.php/view/4561f5d0
Daniel Event Class: http://paste.hostingforoz.com/index.php/view/12162fc1
Description: Class to access and send data to an external script
This class can be used to easily access external scripts and web services, with just a few lines.
Heres an example:
// Create a new instance of the Script Loader.. Using the POST method and the default data type
var sl:ScriptLoader = new ScriptLoader("http://site.tld/webservicescript.php");
// Add a variable to be sent with the request..
sl.addVariable("aVariable", "testScriptLoader");
// Listen for the "on Completed" event, to notify the function "onSessionCheck" when the web service has been loaded..
// DanielEvent is a custom Event class which needs to be included in the project
sl.addEventListener(DanielEvent.COMPLETED, onSessionCheck);
// Finally load the service/script
sl.load();
function onSessionCheck(e:DanielEvent):void {
var data:Object = e.data as Object;
// data now contains the response data in an object.
if(data.myVar != null) trace(data.myVar);
}
A few notes:
The web service script could reply something like "myVar=myValue&anotherVar=anotherValue" and you could then access that using "data.myVar".
Todays code snippet can be accessed using the below url:
Script Loader class: http://paste.hostingforoz.com/index.php/view/4561f5d0
Daniel Event Class: http://paste.hostingforoz.com/index.php/view/12162fc1
Description: Class to access and send data to an external script
This class can be used to easily access external scripts and web services, with just a few lines.
Heres an example:
// Create a new instance of the Script Loader.. Using the POST method and the default data type
var sl:ScriptLoader = new ScriptLoader("http://site.tld/webservicescript.php");
// Add a variable to be sent with the request..
sl.addVariable("aVariable", "testScriptLoader");
// Listen for the "on Completed" event, to notify the function "onSessionCheck" when the web service has been loaded..
// DanielEvent is a custom Event class which needs to be included in the project
sl.addEventListener(DanielEvent.COMPLETED, onSessionCheck);
// Finally load the service/script
sl.load();
function onSessionCheck(e:DanielEvent):void {
var data:Object = e.data as Object;
// data now contains the response data in an object.
if(data.myVar != null) trace(data.myVar);
}
A few notes:
The web service script could reply something like "myVar=myValue&anotherVar=anotherValue" and you could then access that using "data.myVar".
Thursday, June 2, 2011
AS3 Code Snippet - Getting parameters from URL query string
Hello,
Heres a quick code snippet that you can use to get parameters in the url which a swf is hosted on.
E.G: http://mysite.com/myGreatSWF.swf?paramName=paramValue
Code Snippet:
trace(this.loaderInfo.parameters.paramName);
// outputs "paramValue", if the url is "http://mysite.com/myGreatSWF.swf?paramName=paramValue"
loaderInfo.parameters contains a Object with all the parameters in the url requesting the swf, you could use "swfname.swf?test=thetestvalue" for instance, and get it in the swf file using "loaderInfo.parameters.test"
You should also check if the query (test in this case) exists, in order to avoid errors.
Heres a quick code snippet that you can use to get parameters in the url which a swf is hosted on.
E.G: http://mysite.com/myGreatSWF.swf?paramName=paramValue
Code Snippet:
trace(this.loaderInfo.parameters.paramName);
// outputs "paramValue", if the url is "http://mysite.com/myGreatSWF.swf?paramName=paramValue"
loaderInfo.parameters contains a Object with all the parameters in the url requesting the swf, you could use "swfname.swf?test=thetestvalue" for instance, and get it in the swf file using "loaderInfo.parameters.test"
You should also check if the query (test in this case) exists, in order to avoid errors.
Suggestions for future Tutorials
Hello,
Before we can post lots of interesting and useful AS3 Tutorials, we need to know what to post about.
If you have any ideas about what we should post about, please comment them below.
Would you like to see a "How to create a Virtual World" series?
How about a "How to create a PHP Socket and Game server?" series?
Thanks,
AS3 Tutorials
Before we can post lots of interesting and useful AS3 Tutorials, we need to know what to post about.
If you have any ideas about what we should post about, please comment them below.
Would you like to see a "How to create a Virtual World" series?
How about a "How to create a PHP Socket and Game server?" series?
Thanks,
AS3 Tutorials
Subscribe to:
Comments (Atom)