创建动态图像 as2 代码到 as3
所以我有一个在as2中动态创建图像的函数,告诉一些参数,我面临的问题是我需要将此函数添加到具有as3的文件中,因此不兼容,有人可以帮我将其翻译为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);
}
}
所以我像在循环内一样调用它:
for (i=0; i < Proyecto.length; i++) {
...
createImage(imagePro, "nom"+i,"im"+i, i , myurl, "btn"+i);
...
}
例如 getURL(dir, "_blank");
不起作用,我想我可以通过以下方式更改它:
navigateToURL(new URLRequest (dir));
我也知道 getNextHighestDepth()
在 as3 中不可用
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,这是直接翻译的样子:
这在 AS3 术语中是相当令人不愉快的。需要进行大量转换,并且单击处理程序是匿名函数,其执行速度与事件处理程序一样慢。我个人会创建一个可以多次实例化的自定义类,并将引用存储在 Vector 中以便于访问。像这样的东西:
您可以这样使用它:
这里很酷的事情是类中的鼠标事件会冒泡,因此如果您想知道从主代码中单击了哪个图像组件,您可以向舞台添加一个侦听器,并像这样检查事件对象:
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: