Convert Actionscript 3 to Actionscript 2 - actionscript-3

I have an problem to convert AS3 to AS2
Here is my AS3 code
submit.addEventListener("mouseDown", sendData);
function sendData(evt:Event)
{
//for those using PHP
var students:URLRequest = new URLRequest("http://localhost/phpflash/new_student.php");
students.method = URLRequestMethod.POST;
var posts:URLVariables = new URLVariables();
posts.Fullname = Fullname.text;
students.data = posts;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(students);
}

Like #VC.One said, you must learn AS3, AS2 was dropped and actually Flash CC does not support it.
I do not code in AS2 since many, many years. So this code could contain some errors:
submit.onMouseDown = sendData;
function sendData():Void
{
var vars:LoadVars = new LoadVars();
vars.Fullname = Fullname.text;
var target:Object = new Object();
target.onLoad = function(){
trace("vars sended");
}
vars.sendAndLoad("http://localhost/phpflash/new_student.php", target, "POST");
}

Related

Load external swf into bytearray with adobe flash

How can I load external swf into bytearray with adobe flash AS3..
Here is my code..
var my_url1:URLRequest = new URLRequest("SWF/Lesson1.swf");
my_url1.method = URLRequestMethod.GET;
my_url1.contentType = "application/x-shockwave-flash";
var urlloader:URLLoader = new URLLoader(my_url1);
var myByteArray:ByteArray = new ByteArray();
urlloader.data = myByteArray;
It not works well. But it isn't give any error. How can I fix this problem?
You should listen for COMPLETE event and set the data format to BINARY:
var my_url1:URLRequest = new URLRequest("SWF/Lesson1.swf");
var urlloader:URLLoader = new URLLoader(my_url1);
urlloader.dataFormat = URLLoaderDataFormat.BINARY;
urlloader.addEventListener(Event.COMPLETE, function(event:Event):void
{
var myByteArray:ByteArray = URLLoader(event.target).data as ByteArray;
trace(myByteArray.length);
});

Looking to use Firebase with Actionscript 3 / Air

I have found Firebase, and it looks excellent for javascript / HTML5 usage.
But I was wondering if there is also an Actionscript API?
E.g
var myRootRef = new Firebase('https://myprojectname.firebaseIO-demo.com/');
myRootRef.set('Hello World!');
var dataRef = new Firebase('https://SampleChat.firebaseIO-demo.com/users/fred/name/first');
dataRef.on('value', function(snapshot) {
alert('fred’s first name is ' + snapshot.val());
});
So to set data and have listeners for updated data etc.
Thanks for any help
Matt
Doesn't look like there is an AS3 api available but the good news is that they have a rest api which is cross platform that you can write an AS3 wrapper around. (https://www.firebase.com/docs/rest-api.html) That is what I plan to do. I Want to use it with GameBuilder Studio.
If you are planning on embedding your application inside a web page (that you create) you could use an external javascript interface and communicate to firebase through that.
I'm planning on doing this myself to see how it turns out.
Connecting to Firebase using ActionScript 3 only requires the use of URLRequest and URLLoader. The following examples cover the 4 basic operations (CRUD).
To read data from an specific node from your Firebase database:
private function loadNews():void
{
var request:URLRequest = new URLRequest("https://<YOUR-PROJECT-ID>.firebaseio.com/<Node_to_read>.json");
var loader:URLLoader = new URLLoader();
loader.addEventListener(flash.events.Event.COMPLETE, newsLoaded);
loader.load(request);
}
private function newsLoaded(event:flash.events.Event):void
{
trace(event.currentTarget.data);
var rawData:Object = JSON.parse(event.currentTarget.data);
}
To insert data to a specific node:
private function saveEntry(title:String, description:String):void
{
var myObject:Object = new Object();
myObject.title = title;
myObject.description = description;
myObject.timestamp = new Date().getTime();
var request:URLRequest = new URLRequest("https://<YOUR-PROJECT-ID>.firebaseio.com/<Node_to_insert>.json");
request.data = JSON.stringify(myObject);
request.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.addEventListener(flash.events.Event.COMPLETE, entrySent);
loader.load(request);
}
private function entrySent(event:flash.events.Event):void
{
trace(event.currentTarget.data);
}
To delete a specific node:
private function deleteEntry():void
{
var header:URLRequestHeader = new URLRequestHeader("X-HTTP-Method-Override", "DELETE");
var request:URLRequest = new URLRequest("https://<YOUR-PROJECT-ID>.firebaseio.com/<Node_to_delete>.json");
request.method = URLRequestMethod.POST;
request.requestHeaders.push(header);
var loader:URLLoader = new URLLoader();
loader.addEventListener(flash.events.Event.COMPLETE, entryDeleted);
loader.load(request);
}
private function entryDeleted(event:flash.events.Event):void
{
trace(event.currentTarget.data);
}
To update/modify data to a specific node:
private function updateEntry(title:String, description:String):void
{
var header:URLRequestHeader = new URLRequestHeader("X-HTTP-Method-Override", "PATCH");
var myObject:Object = new Object();
myObject.title = title;
myObject.description = description;
var request:URLRequest = new URLRequest("https://<YOUR-PROJECT-ID>.firebaseio.com/journal/<Node_to_modify>.json");
request.data = JSON.stringify(myObject);
request.method = URLRequestMethod.POST;
request.requestHeaders.push(header);
var loader:URLLoader = new URLLoader();
loader.addEventListener(flash.events.Event.COMPLETE, entryUpdated);
loader.load(request);
}
private function entryUpdated(event:flash.events.Event):void
{
trace(event.currentTarget.data);
}
If you want further information I have written detailed Firebase REST guides and examples on how to use ActionScript 3 and Firebase.

Imdb api with flash - as3 - flex

I am trying to use the imdb API, in this case: http://imdbapi.org/
I need to search for a movie by name and get a json, then load an image with the poster obtained.
I'll be using as3 - flex to generate an Air package.
I tried this example, but can't seem to get it right.
import flash.net.*;
var url:String = "http://imdbapi.org/";
var request:URLRequest = new URLRequest(url);
request.method = URLRequestMethod.GET;
var variables:URLVariables = new URLVariables();
variables.name = "Pulp fiction";
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onComplete);
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.load(request);
function onComplete (event:Event):void {
trace(event.target.data);
}
Perhaps you could enlight me with an example of connecting to the api and retrieving that json so that I can load an image with the poster and generate my air package.
Many thanks!
The API seems to want the movie in the q param so change this
variables.name = "Pulp fiction";
to :
variables.q = "Pulp fiction";
To verify : http://imdbapi.org/?q=Pulp%20Fiction
From there getting the poster URL is just a matter of reading the correct property from the JSON string.
private function onComplete (event:Event):void {
var data:Array = JSON.parse(event.target.data);
if(data && data.length)
{
var movie:Object = data[0];
trace(movie.poster);
}
}

Sending data from flash to php using post method as2

I am using following code in as3:
var Request:URLRequest = new URLRequest();
var xmlMain:XML=new XML();
var urlXmlLoader:Loader = new Loader();
var myVars:URLVariables = new URLVariables();
myVars.RequestXml = xmlMain;
Request.url = "http://www.xyz.php"; //some php url
Request.method = URLRequestMethod.POST;
Request.data = myVars;
urlXmlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlXmlLoader.addEventListener(Event.COMPLETE, getData);
urlXmlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
urlXmlLoader.load(Request);
Now I have an as2 project where I need to do the same. How can it be done in as2??
This is probably the best tutorial on HTTP requests in AS2: http://www.sephiroth.it/tutorials/flashPHP/loadVars/

LocalConnection var into URLRequest

i use LocalConnection between two swf in the same page.
What i'm trying to do is to use a String sent from one swf to the other, as variable into my URLRequest...
So i can trace "myVar" into the function chemin, but i didn't find how to use it into URLRequest
thank's for your help
swf that receive the var :
var lc:LocalConnection=new LocalConnection();
lc.client=this;
lc.connect("callBig");
function chemin(myVar:String){
trace(myVar)
}
var chargementXML:URLLoader = new URLLoader();
var fichier:URLRequest = new URLRequest(myVar);
Some references to help you out.
URLRequest.data: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html?filter_flex=4.1&filter_flashplayer=10.2&filter_air=2.6#data
URLVariables: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLVariables.html
So, if you want to pass some variables in your request, you do the following:
Create new URLVariables() object
Assign it's reference to URLRequest.data field.
var fichier:URLRequest = new URLRequest();
var urlVars:URLVariables = new URLVariables();
urlVars["myVarName"] = myVar;
fichier.data = urlVars;
This way your server side app will recieve a variable myVarName with value of myVar.
var lc:LocalConnection=new LocalConnection();
lc.client=this;
lc.connect("callBig");
var receivedVar:String = "";
// somewhere else
function chemin(myVar:String){
receivedVar = myVar;
}
// later
var chargementXML:URLLoader = new URLLoader();
var vars:URLVariables = new URLVariables();
vars.myVar = receivedVar;
chargementXML.data = vars;
var fichier:URLRequest = new URLRequest(myVar);