我有一个奇怪的问题。我设置
时可以触发Event.COMPLETEimage.source = byteArray;
BUT
当我操作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!
由于 Subrat
答案 0 :(得分:2)
所以这里的课程是SWFLoader(Image扩展SWFLoader)。如果你传入ByteArray或url而不是添加适当的监听器。你做的是给它一个Bitmap,它是一个显示对象。以下是将Bitmap加载到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);
}
网址:
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添加到您的位图。