Copy link to clipboard
Copied
Hello everyone,
I am a huge noob in flash, I am to change a code from AS2 to AS3, this function (is a display tracking) should send a request for a server, and load the movie after, please tell me how to change it, some alternatives, some hints, but remember, keep the level low.
var EMISJE = "http://server.com/_"+Math.ceil(Math.random()*1000000000)+"/id=234";
_root.MAI_catchEmision = function(url) {
if (_root.MAI_catchEmision_run == undefined || _root.MAI_catchEmision_run == false) {
_root.createEmptyMovieClip("MAI_catchEmision_target_mc",_root.getNextHighestDep th());
_root.MAI_catchEmision_run = true;
_root.MAI_catchEmision_target_mc._x = Stage.width+10;
_root.MAI_catchEmision_target_mc._y = Stage.height+10;
_root.MAI_catchEmision_target_mc.loadMovie(url);
}
}
Thank you very much
Copy link to clipboard
Copied
I don't know what significance the first line has to the rest of the code, but it would not change.
var EMISJE = "http://server.com/_"+Math.ceil(Math.random()*1000000000)+"/id=234";
function MAI_catchEmision (url) {
if (MAI_catchEmision_run == undefined || MAI_catchEmision_run == false) {
var MAI_catchEmision_target_mc:MovieClip = new MoiveClip();
addChild(MAI_catchEmision_target_mc);
MAI_catchEmision_run = true;
MAI_catchEmision_target_mc._x = stage.stageWidth+10;
MAI_catchEmision_target_mc._y = stage.stageHeight+10;
var ldr:Loader = new Loader();
var req:URLRequest = new URLRequest(url);
var ldr.load(req);
MAI_catchEmision_target_mc.addChild(ldr);
}
}
Copy link to clipboard
Copied
sorry fogot the last line:
_root.MAI_catchEmision(EMISJE);
so does this code work in AS3??
Copy link to clipboard
Copied
MAI_catchEmision(EMISJE);
What type of file is linked by that URL? I have my doubts it would work even with AS2 if that is not an image or swf file.
Copy link to clipboard
Copied
its an jpg file
Copy link to clipboard
Copied
I still have my doubts mainly because I would epect to see a "jpg" somewhere at the end of that url in order for it to work, but if it somehow does deliver a jpeg image to the Loader, then it should work. The only way to be sure is to try it, and that's up to you.
Copy link to clipboard
Copied
Thanks for your help,
I get only one error at the line:
var ldr.load(req);
The error is:
1086: Syntax error: expecting semicolon before dot.
What could be done?
Copy link to clipboard
Copied
remove the var keyword
ldr.load(req);
By the way, you can add a Loader instance directly to the stage since it's a DisplayObjectContainer, rather than having to create a MovieClip instance first.
So this:
var MAI_catchEmision_target_mc:MovieClip = new MoiveClip();
addChild(MAI_catchEmision_target_mc);
MAI_catchEmision_run = true;
MAI_catchEmision_target_mc._x = stage.stageWidth+10;
MAI_catchEmision_target_mc._y = stage.stageHeight+10;
var ldr:Loader = new Loader();
var req:URLRequest = new URLRequest(url);
ldr.load(req);
MAI_catchEmision_target_mc.addChild(ldr);
Can be reduced to:
MAI_catchEmision_run = true;
var req:URLRequest = new URLRequest(url);
var ldr:Loader = new Loader();ldr.x = stage.stageWidth+10;
ldr.y = stage.stageHeight+10;
ldr.load(req);
addChild(ldr);
read the docs on Loader:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Loader.html
Also note that properties that had an underscore in AS2 no longer have one in AS3.
_x -> x
_y -> y
_width -> width
_height -> height
etc..
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more