开发者

Adobe Flex: Event.COMPLETE for Image does not fire when image loaded from Bitmap

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜