ActionScript 3.0 获取已加载影片剪辑图像的索引 [CLICK 事件]

发布于 2024-10-11 20:12:20 字数 1817 浏览 3 评论 0原文

我正在将一组缩略图从数组[硬编码]加载到舞台上的影片剪辑符号中。我有两个数组,其中缩略图和全尺寸图像具有相同的索引号。在许多示例中,“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小女人ら 2024-10-18 20:12:20

contentLoaderInfo 属性返回一个 LoaderInfo 类。您可以在此处查看其属性:

http:// help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/LoaderInfo.html

The contentLoaderInfo property returns a LoaderInfo class. You can view its properties here:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/LoaderInfo.html

懒猫 2024-10-18 20:12:20

您可以使用 array.indexOf() 返回对象的索引。由于我不知道您的其余代码,这里有一个大概的示例:

function thumbClicked (ev:MouseEvent) : void {

    var index:int = thumbnails.indexOf ( ev.target.contentLoaderInfo.url );
    loader.load ( new URLRequest (fullSizeImages[index]) ) ;
}

编辑

由于我不知道您使用的确切代码,我假设您将图片的整个路径存储在你的数组。在您的代码中,您在前面添加“images/”,因此代码应该是:

function thumbClicked (ev:MouseEvent) : void {

    var index:int = thumbnails.indexOf ( ev.target.contentLoaderInfo.url.substring (7)); 
    // 7 is the length of "images/", so substring returns only the filename part.

    loader.load ( new URLRequest (fullSizeImages[index]) ) ;
}

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:

function thumbClicked (ev:MouseEvent) : void {

    var index:int = thumbnails.indexOf ( ev.target.contentLoaderInfo.url );
    loader.load ( new URLRequest (fullSizeImages[index]) ) ;
}

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:

function thumbClicked (ev:MouseEvent) : void {

    var index:int = thumbnails.indexOf ( ev.target.contentLoaderInfo.url.substring (7)); 
    // 7 is the length of "images/", so substring returns only the filename part.

    loader.load ( new URLRequest (fullSizeImages[index]) ) ;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文