Skip to main content
Participant
May 11, 2017
Answered

AS2 to AS3 help!

  • May 11, 2017
  • 1 reply
  • 381 views

Hello,

I'm only a beginner at coding and need to migrate AS2 code to AS3 code. I get this error code: 'Call to possibly undefined method eval.' and don't know how to fix it.

Below is just a section of the code where the error is- but if you need the whole thing I can send that too.

Thanks

};

foam_btn.onRelease = function() {

  // this._visible = false;

  videoLoop_mc.gotoAndPlay("exit");

  triangle_mc.gotoAndPlay("oxygenHeat");

  new Tween(eval(currentExt), "alpha", None.easeNone, 100, 0, fadeTime, false);

  currentExt = "foamInfo_mc";

  new Tween(eval(currentExt), "alpha", None.easeNone, 0, 100, fadeTime, false);

  currentFactor = "oxygen_mc";

  new Tween(eval(currentFactor), "alpha", None.easeNone, 100, 0, fadeTime, false);

  currentFactor = "heat_mc";

  new Tween(eval(currentFactor), "alpha", None.easeNone, 100, 0, fadeTime, false);

  nextFade();

  foamTrigger = true;

  buttonDisable();

  this.gotoAndStop(1);

  visited(foam_btn,foamTrigger);

  twoFactors = true;

};

This topic has been closed for replies.
Correct answer Colin Holgate

The button onRelease part can't work, you need to addEventListener instead. Which would make it start like:

foam_btn.addEventListener(MouseEvent.CLICK,foamclicked);

function foamclicked(e:MouseEvent){

// etc

You don't show where currentExt is set up for the first time, but in any case I would put the symbol name into the tween, instead of using eval(). So, like:

  new Tween(foamInfo_mc, "alpha", None.easeNone, 0, 100, fadeTime, false);

instead of:

  currentExt = "foamInfo_mc";

  new Tween(eval(currentExt), "alpha", None.easeNone, 0, 100, fadeTime, false);

It is possible that this["foamInfo_mc"] would behave the same as eval("foamInfo_mc"). But no need to do that, if the line I gave works.

1 reply

Colin Holgate
Colin HolgateCorrect answer
Inspiring
May 11, 2017

The button onRelease part can't work, you need to addEventListener instead. Which would make it start like:

foam_btn.addEventListener(MouseEvent.CLICK,foamclicked);

function foamclicked(e:MouseEvent){

// etc

You don't show where currentExt is set up for the first time, but in any case I would put the symbol name into the tween, instead of using eval(). So, like:

  new Tween(foamInfo_mc, "alpha", None.easeNone, 0, 100, fadeTime, false);

instead of:

  currentExt = "foamInfo_mc";

  new Tween(eval(currentExt), "alpha", None.easeNone, 0, 100, fadeTime, false);

It is possible that this["foamInfo_mc"] would behave the same as eval("foamInfo_mc"). But no need to do that, if the line I gave works.

Rachyy95Author
Participant
May 11, 2017

Thank you for you help! That worked fine.

Can you help me with this bit aswell ? Or point me in the right direction...

water_btn.onRollOut = water_btn.onDragOut=water_btn.onReleaseOutside=function () {

  visited(water_btn,waterTrigger);

};

powder_btn.onRollOut = powder_btn.onDragOut=powder_btn.onReleaseOutside=function () {

  visited(powder_btn,powderTrigger);

};

foam_btn.onRollOut = foam_btn.onDragOut=foam_btn.onReleaseOutside=function () {

  visited(foam_btn,foamTrigger);

};

co2_btn.onRollOut = co2_btn.onDragOut=co2_btn.onReleaseOutside=function () {

  visited(co2_btn,co2Trigger);

};

blanket_btn.onRollOut = blanket_btn.onDragOut=blanket_btn.onReleaseOutside=function () {

  visited(blanket_btn,blanketTrigger);

};

Colin Holgate
Inspiring
May 11, 2017

The general case is that instead of btn.onSomething = function() you do btn.addEventListener("eventtype",functionname). This page shows you what event types there are:

MouseEvent - Adobe ActionScript® 3 (AS3 ) API Reference

There are some event types that don't exist in AS3, that were in AS2, and you would need to find another way to get the same results.

It could be worth you trying to figure out some of that for yourself, and then ask about the bits you're stuck on.