PDA

View Full Version : Eval replacement in AS3



lambros
June 19th, 2007, 09:55 AM
var currentPage="contentHome_mc";

contentHome_mc.gotoAndPlay("on");

//Functions
function animateOn(page:String) {
eval(page).gotoAndPlay("on");
}

function animateOff(page:String) {
eval(page).gotoAndPlay("off")
}

function onHomeclick(evt:MouseEvent) {
if (currentPage != "contentHome_mc") {
animateOff(currentPage);
animateOn("contentHome_mc");
currentPage="contentHome_mc";
}
}

function onAboutclick(MouseEvent) {
if (currentPage!= "contentAbout_mc") {
animateOff(currentPage);
animateOn("contentAbout_mc");
currentPage="contentAbout";
}
}

function onProductsclick(MouseEvent) {
if (currentPage!= "contentProducts_mc") {
animateOff(currentPage);
animateOn("contentProducts_mc");
currentPage="contentProducts";
}
}


//Menu Button actions
home_mc.addEventListener(MouseEvent.CLICK, onHomeclick);
products_mc.addEventListener(MouseEvent.CLICK, onProductsclick);
about_mc.addEventListener(MouseEvent.CLICK, onAboutclick);



hey guys can anyone help me out please ? i am watching the learnflash building a flash site with flash 8 video and i am trying to make the exact things but instead of actionscript 2 with AS3.so far i did great but now that the functions and variables started gettind involved for lots actions it seems that there are many dieferences....

what can i put instead of the "eval" so i can havce the same result as the eval ?????? everything else works just that. please tell me how to do it.....

if you didn't understand my problem is how can i make the variable of the function gets a value from the event listeners....and convert the string it gets to a code so to complete the function!

bigarth
June 19th, 2007, 01:28 PM
you should use getChildByName (string). this will allow you to retrieve a child element of a particular DisplayObject (such as a MovieClip).

lambros
June 19th, 2007, 02:57 PM
so you mean that in the place of eval i should put your code ? like this ?



function animateOn(page:String) {
getChildByName (string)(page).gotoAndPlay("on");
}

edit: ok i found it...thanks man!!!!

is there any way to find out how to replace actionscript 2 to 3 ? like this situation ? cause i really need it !!!

bigarth
June 19th, 2007, 03:00 PM
the (string) was just a reference for you. it would look like:

function animateOn (page:String) {
getChildByName (page).gotoAndPlay ("on");
}

lambros
June 19th, 2007, 03:36 PM
yeah i figured that out after two experiments....you unsderstand that i am very noob yet :blush: :geek:

thanks again....

i 'd like to ask you is there any site any ebbok or video that i can use very time i have a script in AS2 and i want to make it AS3 ?? cause i have a complete tutorial on making a flash with preloaders popups forms everything but unfortunately it's for flash 8 and AS2. i try to mak every excample from there to as3 but it's pretty difficult when variables and functions are involved cause the structure is different...
so is thre any way to find how the AS2 is made to AS3 ??????

bigarth
June 19th, 2007, 03:52 PM
not that i know of. i usually find out my information by google-ing "actionscript 3" and whatever term i'm looking to replace. for instance, for your original question i bet you could have found an answer by searching "actionscript 3 eval" (without quotes)

lambros
June 20th, 2007, 03:54 AM
ok man thanks for the help

Dimitree
June 20th, 2007, 06:54 AM
Try this link http://livedocs.adobe.com/flex/2/langref/migration.html

Also: http://www.5etdemi.com/convert/

lambros
June 20th, 2007, 04:07 PM
hey dimitree thanks for the links but the first one is in the flash help too and it doesn't say what to put in AS3 instead of AS2.like eval it just says removed .....nothing else......

as for the second one i didn't understand how to use it ? is it just for classes ???????

Dimitree
June 21st, 2007, 12:00 PM
hey dimitree thanks for the links but the first one is in the flash help too and it doesn't say what to put in AS3 instead of AS2.like eval it just says removed .....nothing else......

as for the second one i didn't understand how to use it ? is it just for classes ???????

Yes it s only for classes.

dthought
June 26th, 2007, 01:04 AM
...and read senocular's AS3 Tip of the Day in the ActionScript 3 forum.

And remain calm when things don't work the way you want them to ;)