ActionScript 3.0 获取已加载影片剪辑图像的索引 [CLICK 事件]
我正在将一组缩略图从数组[硬编码]加载到舞台上的影片剪辑符号中。我有两个数组,其中缩略图和全尺寸图像具有相同的索引号。在许多示例中,“event.currentTarget.contentLoaderInfo.url”返回所选图像的完整路径。我只想要索引号。
Adobe 并没有让我很容易从 contentLoaderInfo 中找出哪些其他属性可供我使用。 “SelectedIndex”或类似的东西可用吗?
鼓舞人心的 AS 程序员在哪里可以找到可用的 contentLoaderInfo 属性和/或方法? url 是我们在这里唯一可用的东西吗?
有更好的方法吗?
提前致谢。
编辑:
var thumbnails:Array = ["tn_2010OpenHouse_00.jpg","tn_2010OpenHouse_01.jpg"];
var images:Array = ["2010OpenHouse_00.jpg","2010OpenHouse_01.jpg"];
var thumbX:Number = 10;
var thumbY:Number = 623;
var loader:Loader = new Loader();
loader.load(new URLRequest("images/" + images[0]));
addChild(loader);
loadThumbs();
function loadThumbs():void
{
var thumbLoader:Loader;
var container:Sprite = new Sprite();
container.width = 100;
addChild(container);
container.buttonMode = true;
for (var i:uint = 0; i < thumbnails.length; i++)
{
thumbLoader = new Loader();
thumbLoader.load(new URLRequest("images/" + thumbnails[i]));
thumbLoader.x = thumbX;
thumbLoader.y = thumbY;
thumbX += 100;
container.addChild(thumbLoader);
thumbLoader.addEventListener(MouseEvent.CLICK, thumbClicked);
container.width += 100;
addChild(thumbLoader);
}
stop();
}
function thumbClicked(ev:MouseEvent):void
{
//weltraumpirat's example
var index:int = thumbnails.indexOf ( ev.target.contentLoaderInfo.url );
trace("Index= "+ index);
//trying a different approach as well
index = thumbnails.indexOf ( ev.currentTarget.contentLoaderInfo.url );
trace("Index= "+ index);
loader.load(new URLRequest("images/" + images[index]));
}
输出: 指数= -1 指数= -1 错误#2044:未处理的 IOErrorEvent:。 text=错误#2035:找不到 URL。
I am loading a set of thumbnail images from an array [hard coded] into a movieclip symbol on the stage. I have two arrays with the thumbnail and the full size image having the same index number. In many examples, "event.currentTarget.contentLoaderInfo.url" returns the full path to the image selected. i just want the index number.
Adobe does not make is easy to figure out what other properties are available to me from the contentLoaderInfo. Is 'SelectedIndex' or something like that available?
Where does an inspiring AS programmer find the contentLoaderInfo properties and or methods available? Is url the only thing that us usable here?
Is there a better approach?
Thanks in advance.
Edit:
var thumbnails:Array = ["tn_2010OpenHouse_00.jpg","tn_2010OpenHouse_01.jpg"];
var images:Array = ["2010OpenHouse_00.jpg","2010OpenHouse_01.jpg"];
var thumbX:Number = 10;
var thumbY:Number = 623;
var loader:Loader = new Loader();
loader.load(new URLRequest("images/" + images[0]));
addChild(loader);
loadThumbs();
function loadThumbs():void
{
var thumbLoader:Loader;
var container:Sprite = new Sprite();
container.width = 100;
addChild(container);
container.buttonMode = true;
for (var i:uint = 0; i < thumbnails.length; i++)
{
thumbLoader = new Loader();
thumbLoader.load(new URLRequest("images/" + thumbnails[i]));
thumbLoader.x = thumbX;
thumbLoader.y = thumbY;
thumbX += 100;
container.addChild(thumbLoader);
thumbLoader.addEventListener(MouseEvent.CLICK, thumbClicked);
container.width += 100;
addChild(thumbLoader);
}
stop();
}
function thumbClicked(ev:MouseEvent):void
{
//weltraumpirat's example
var index:int = thumbnails.indexOf ( ev.target.contentLoaderInfo.url );
trace("Index= "+ index);
//trying a different approach as well
index = thumbnails.indexOf ( ev.currentTarget.contentLoaderInfo.url );
trace("Index= "+ index);
loader.load(new URLRequest("images/" + images[index]));
}
Output:
Index= -1
Index= -1
Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
contentLoaderInfo
属性返回一个LoaderInfo
类。您可以在此处查看其属性:http:// help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/LoaderInfo.html
The
contentLoaderInfo
property returns aLoaderInfo
class. You can view its properties here:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/LoaderInfo.html
您可以使用 array.indexOf() 返回对象的索引。由于我不知道您的其余代码,这里有一个大概的示例:
编辑:
由于我不知道您使用的确切代码,我假设您将图片的整个路径存储在你的数组。在您的代码中,您在前面添加“images/”,因此代码应该是:
You can use array.indexOf() to return an object's index. Since I don't know the rest of your code, here's an approximate example:
Edit:
Since I didn't know the exact code you were using, I assumed you store the entire path to the picture in your array. In your code, you prepend "images/", so the code should be: