So I have a function to create images dynamically in as2, telling some parameters, the problem I am facing is that I need to add this function to a file that has as3, so is incompatible, can anyone please help me translate it to as3?
function goGetUrl(dir:String){
getURL(dir, "_blank");
}
function createImage(str:String,
movieName:String,
nombreIma:String,
index:Number,
dir:String,
buttonName:String
)
{
var mc:MovieClip = MYMOVIECLIP.createEmptyMovieClip(movieName, MYMOVIECLIP.getNextHighestDepth());
var image:MovieClip = mc.createEmptyMovieClip(nombreIma, mc.getNextHighestDepth());
image.loadMovie(str);
image._y = (index * 160);
image._x = 10;
mc.onRelease = function(){
goGetUrl(dir);
}
target = MYMOVIECLIP.attachMovie("MYCUSTOMBUTTONONLIBRARY",buttonName,MYMOVIECLIP.getNextHighestDepth(),{_x: 300, _y: (image._y + 60) });
target.onRelease = function(){
goGetUrl(dir);
}
}
So I call it like inside a loop:
for (i=0; i < Proyecto.length; i++) {
...
createImage(imagePro, "nom"+i,"im"+i, i , myurl, "btn"+i);
...
}
For example the getURL(dir, "_blank"); does not work, I think I can chage it by:
navigateToURL(new URLRequest (dir));
also I know that getNextHighestDepth() is not available in as3
First, here’s how is looks as a direct translation:
This is quite unpleasant in AS3 terms. There is lots of casting required and the click handlers are anonymous functions, which is about as slow to execute as an event handler will get. I would personally create a custom class that you can instantiate multiple times, and store the references in a Vector for easy access. Something like this:
You could use that like this:
The cool thing here is that mouse event in the class will bubble, so if you wanted to know which image component had been clicked from your main code you would add a listener to the stage, and check the event object like this: