【问题标题】:How to set an event listener for mx:image to kick in after image loads如何为 mx:image 设置事件侦听器以在图像加载后启动
【发布时间】:2010-09-28 03:15:13
【问题描述】:

有没有办法在 Flex 加载 mx:image 后调度事件?我在外部加载图像并且在加载之前不知道宽度/高度。在加载之前调用图像的宽度/高度时出现异常。

【问题讨论】:

    标签: apache-flex flex4


    【解决方案1】:

    你应该使用加载器,在这种情况下,就像我在下面提到的代码中使用的那样

    私有 var loader:loader = new Loader(); loader.load(new URLRequest(rp_product.dataProvider[i].@source)); loader.contentLoaderInfo.addEventListener(Event.COMPLETE,productLoadingComplete);
    loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,productLoadingError);

    rp_product.dataProvider[i].@source,这里rp_product是我的repeater的id,

    您只需在此处提供您要加载的图像源,现在您有 productLoadingComplete() 方法和 productLoadingError() 方法可用,即使您想在图像进程中进行某些操作,所以使用此代码:

    loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onImageLoadProgress);

    通过这种方式,你可以加载外部图像,我希望这是你想要的

    【讨论】:

    • 完成后如何将加载器的结果设置为图像?为 mx:image 设置源属性不会触发图像自动加载图像吗?
    • 私有函数 productLoadingComplete(event:Event):void { Image(Canvas(tile_product.getChildAt(i)).getChildAt(0)).source = event.target.content; Canvas(tile_product.getChildAt(i)).addEventListener(MouseEvent.CLICK,productSelected); removeSwfLoader(); }
    • ohhh,对不起,我那天已经写了这个函数,看到这是我的productLoadingComplete()函数,它被调用,当加载器加载图像时,只需使用event.target .content(即图片)
    • 对不起,亲爱的,这有点复杂,要理解,但是当我们这样做时很容易,而且还有一件事,很快就学会了,因为在以后的编程中,至少如果我说话abt我,那我必须非常使用这个,
    • 在你的问题中,当我们不确定图像或外部数据需要多少时间来加载时,我们使用加载器,在 loader.contentloaderInfo 上,有几个事件侦听器,就像我有用过,只是我使用了内置的事件监听器,并调用了自己的函数,希望这有帮助,如果这仍然是一个问题,我会给你一个演示应用程序
    【解决方案2】:

    您可以为 flash.events.Event.COMPLETE 事件附加监听器。图像加载完成时触发。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-26
      • 1970-01-01
      • 2011-08-16
      • 1970-01-01
      相关资源
      最近更新 更多