嗨iam試圖加載一些外部jpeg在As3中。 它在Flash中可以很好地在本地運行,但它並不適用於我的服務器。 我的應用程序還同時加載了一個YouTube視頻。Flash As3加載程序問題
function drawResult(index,videoID,song_title,thumbnail:String=null)
{
var theClip:resultRowClip=new resultRowClip();
_clip.addChild(theClip);
myArray[index] = new Array(videoID,theClip);
theClip.y=0+(43*(index-1));
theClip.rowText.text = song_title;
theClip.rowBack.visible = false;
if (thumbnail != ""){
theClip.tHolder.visible=true;
loadImage(thumbnail,index);
}
}
function loadImage(url:String,index):void
{
//this.myClip.myText.text += "load image";
// Set properties on my Loader object
var imageLoader:Loader = new Loader();
imageLoader.load(new URLRequest(url));
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function (evt:Event){imageLoaded(evt,index)});
}
function imageLoaded(evt,id):void
{
//this.myClip.myText.text += "id : evt : " + evt.status;
// Load Image
var image:Bitmap = new Bitmap(evt.target.content.bitmapData);
myArray[id][1].tHolder.addChild(image);
myArray[id][1].tHolder.width=myArray[id][1].tHolder.width*0.35;
myArray[id][1].tHolder.height=myArray[id][1].tHolder.height*0.35;
}
有沒有人知道問題是什麼?
**我添加了兩個Evenet聽衆從IO錯誤:
imageLoader.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
這是處理錯誤的函數:
private function ioErrorHandler(event:IOErrorEvent):void {
this.myClip.myText.text +=("ioErrorHandler: " + event);
}
反正,我沒有錯誤...
我也試圖在imageLoader.load之前移動監聽器,但它仍然是一樣的...沒有錯誤,也沒有加載數據。
我我的代碼更改爲patrikS建議:
function loadImage(url:String,index):void
{
//this.myClip.myText.text += "load image";
// Set properties on my Loader object
//if (index != 1) return;
var imageLoader:Loader = new Loader();
imageLoader.name = index.toString();
//myArray[index][1].addChild(imageLoader);
//imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function (evt:Event){imageLoaded(evt,index)});
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
imageLoader.load(new URLRequest(url));
}
我現在completeHandler函數(TNX patrikS):
private function completeHandler(evt:Event):void{
//this.myClip.myText.text += "id : evt : " + evt.status;
// Load Image
trace("evt target loader name : "+ evt.target.loader.name);
evt.target.removeEventListener(Event.COMPLETE, completeHandler);
var image:Bitmap = new Bitmap(evt.target.content.bitmapData);
myArray[evt.target.loader.name][1].tHolder.addChild(image);
myArray[evt.target.loader.name][1].tHolder.width=myArray[evt.target.loader.name][1].tHolder.width*0.35;
myArray[evt.target.loader.name][1].tHolder.height=myArray[evt.target.loader.name][1].tHolder.height*0.35;
//trace (hadar.y + "Y/X" + hadar.x);
}
它仍然只在閃光燈IDE和dosent工作在任何瀏覽器中運行...
添加一個錯誤事件的事件監聽器併發布問題是什麼。 – Kricket 2010-10-18 08:20:01
我試圖添加2個偵聽器:imageLoader.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler); imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,事件。ioErrorHandler);並沒有響應...所以這意味着沒有錯誤..?!? – Hadar 2010-10-18 08:32:07
這些文件位於何處?您是否在本地測試.swf,但在服務器上使用.html頁面進行測試? – Joony 2010-10-18 09:48:33