Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS2 to AS3 help please (hints or anything)

New Here ,
Oct 06, 2009 Oct 06, 2009

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

TOPICS
ActionScript
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 06, 2009 Oct 06, 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);
}
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 06, 2009 Oct 06, 2009

sorry fogot the last line:

_root.MAI_catchEmision(EMISJE);

so does this code work in AS3??

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 06, 2009 Oct 06, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 06, 2009 Oct 06, 2009

its an jpg file

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 06, 2009 Oct 06, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 06, 2009 Oct 06, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 06, 2009 Oct 06, 2009
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines