Adobe Flex:从位图加载图像时不会触发图像的 Event.COMPLETE

发布于 2024-08-18 01:33:06 字数 642 浏览 1 评论 0原文

我有一个奇怪的问题。当我设置时,我可以让 Event.COMPLETE 触发

image.source = byteArray;

,但是

当我操作 byteArray - 将其转换为 Bitmap 并使用 image.source 或 image.load 加载它时,位图会正确加载到 Image 组件中;但是 Event.COMPLETE 永远不会触发。这里可能出了什么问题?我也添加了一个完整的事件列表!我的来源如下:

                var bmp:Bitmap = scaleBitmapData(bitmapData,280,220);
                imgPreview.addEventListener(Event.COMPLETE,onPreviewImageCompleted); // never fires
                imgPreview.visible = false;
                imgPreview.load(bmp); // does not work with .source either; image is displayed but Event.Complete never fires!

谢谢 苏拉特

I have a weird issue. I can get Event.COMPLETE to fire when I set

image.source = byteArray;

BUT

When I manipulate the byteArray - convert it to Bitmap and use image.source or image.load to load it, the bitmap gets loaded properly into the Image component; BUT Event.COMPLETE never fires. What might be wrong here? I have added an event lister for complete too! My source is as follows:

                var bmp:Bitmap = scaleBitmapData(bitmapData,280,220);
                imgPreview.addEventListener(Event.COMPLETE,onPreviewImageCompleted); // never fires
                imgPreview.visible = false;
                imgPreview.load(bmp); // does not work with .source either; image is displayed but Event.Complete never fires!

Thanks
Subrat

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

锦欢 2024-08-25 01:33:06

所以这里使用的类是 SWFLoader(Image 扩展了 SWFLoader)。如果您传入 ByteArray 或 url,它会添加适当的侦听器。您所做的就是向其提供一个位图,它是一个显示对象。下面是将位图加载到图像中的重要代码:

 else if (classOrString is DisplayObject)
 {
     contentHolder = child = DisplayObject(classOrString);
     addChild(child);
     contentLoaded();
 }

ByteArray:

else if (byteArray)
{
    loader = new FlexLoader();
    contentHolder = child = loader;
    addChild(child);

    loader.contentLoaderInfo.addEventListener(
        Event.COMPLETE, contentLoaderInfo_completeEventHandler);
    loader.contentLoaderInfo.addEventListener(
        Event.INIT, contentLoaderInfo_initEventHandler);
    loader.contentLoaderInfo.addEventListener(
        IOErrorEvent.IO_ERROR, contentLoaderInfo_ioErrorEventHandler);
    loader.contentLoaderInfo.addEventListener(
        Event.UNLOAD, contentLoaderInfo_unloadEventHandler);

    // if loaderContext null, it will use default, which is AppDomain
    // of child of Loader's context
    loader.loadBytes(byteArray, loaderContext);
}

a url:

else if (url)
{
    // Create an instance of the Flash Player Loader class to do all the work
    loader = new FlexLoader();
    contentHolder = child = loader;

    // addChild needs to be called before load()
    addChild(loader);

    // Forward the events from the Flash Loader to anyone
    // who has registered as an event listener on this Loader.
    loader.contentLoaderInfo.addEventListener(
        Event.COMPLETE, contentLoaderInfo_completeEventHandler);
    loader.contentLoaderInfo.addEventListener(
        HTTPStatusEvent.HTTP_STATUS, contentLoaderInfo_httpStatusEventHandler);
    loader.contentLoaderInfo.addEventListener(
        Event.INIT, contentLoaderInfo_initEventHandler);
    loader.contentLoaderInfo.addEventListener(
        IOErrorEvent.IO_ERROR, contentLoaderInfo_ioErrorEventHandler);
    loader.contentLoaderInfo.addEventListener(
        Event.OPEN, contentLoaderInfo_openEventHandler);
    loader.contentLoaderInfo.addEventListener(
        ProgressEvent.PROGRESS, contentLoaderInfo_progressEventHandler);
    loader.contentLoaderInfo.addEventListener(
        SecurityErrorEvent.SECURITY_ERROR, contentLoaderInfo_securityErrorEventHandler);
    loader.contentLoaderInfo.addEventListener(
        Event.UNLOAD, contentLoaderInfo_unloadEventHandler); 
...[this goes on for awhile]

这样您就明白了要点。不要将其转换为位图,您将获得完整的事件。您还可以将 ADDED_TO_STAGE 添加到位图。

So the class in play here is SWFLoader (Image extends SWFLoader). If you passed in the ByteArray or a url than it adds the appropriate listener. What you've done is fed it a Bitmap, which is a display object. Here is the important code that is loading a Bitmap into an Image:

 else if (classOrString is DisplayObject)
 {
     contentHolder = child = DisplayObject(classOrString);
     addChild(child);
     contentLoaded();
 }

ByteArray:

else if (byteArray)
{
    loader = new FlexLoader();
    contentHolder = child = loader;
    addChild(child);

    loader.contentLoaderInfo.addEventListener(
        Event.COMPLETE, contentLoaderInfo_completeEventHandler);
    loader.contentLoaderInfo.addEventListener(
        Event.INIT, contentLoaderInfo_initEventHandler);
    loader.contentLoaderInfo.addEventListener(
        IOErrorEvent.IO_ERROR, contentLoaderInfo_ioErrorEventHandler);
    loader.contentLoaderInfo.addEventListener(
        Event.UNLOAD, contentLoaderInfo_unloadEventHandler);

    // if loaderContext null, it will use default, which is AppDomain
    // of child of Loader's context
    loader.loadBytes(byteArray, loaderContext);
}

a url:

else if (url)
{
    // Create an instance of the Flash Player Loader class to do all the work
    loader = new FlexLoader();
    contentHolder = child = loader;

    // addChild needs to be called before load()
    addChild(loader);

    // Forward the events from the Flash Loader to anyone
    // who has registered as an event listener on this Loader.
    loader.contentLoaderInfo.addEventListener(
        Event.COMPLETE, contentLoaderInfo_completeEventHandler);
    loader.contentLoaderInfo.addEventListener(
        HTTPStatusEvent.HTTP_STATUS, contentLoaderInfo_httpStatusEventHandler);
    loader.contentLoaderInfo.addEventListener(
        Event.INIT, contentLoaderInfo_initEventHandler);
    loader.contentLoaderInfo.addEventListener(
        IOErrorEvent.IO_ERROR, contentLoaderInfo_ioErrorEventHandler);
    loader.contentLoaderInfo.addEventListener(
        Event.OPEN, contentLoaderInfo_openEventHandler);
    loader.contentLoaderInfo.addEventListener(
        ProgressEvent.PROGRESS, contentLoaderInfo_progressEventHandler);
    loader.contentLoaderInfo.addEventListener(
        SecurityErrorEvent.SECURITY_ERROR, contentLoaderInfo_securityErrorEventHandler);
    loader.contentLoaderInfo.addEventListener(
        Event.UNLOAD, contentLoaderInfo_unloadEventHandler); 
...[this goes on for awhile]

So you get the gist here. Don't convert it to a Bitmap and you'll get your complete event. You could also add ADDED_TO_STAGE to your Bitmap.

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