Skip to main content
New Participant
October 6, 2009
Question

AS2 to AS3 help please (hints or anything)

  • October 6, 2009
  • 1 reply
  • 967 views

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

This topic has been closed for replies.

1 reply

Ned Murphy
Brainiac
October 6, 2009

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);
}
}

ghostly_1Author
New Participant
October 6, 2009

sorry fogot the last line:

_root.MAI_catchEmision(EMISJE);

so does this code work in AS3??

Muzak
Inspiring
October 6, 2009

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?


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..