我有以下兩類:我自定義的AS3圖像加載的類加載圖像兩次......不是預期的行爲
每一個鏈接到庫中的元件。 dynamic_single_image和dynamic_image,分別。
我將dynamic_image的一個實例拖動到我的時間軸上...並基於movieclip實例的名稱...我使用代碼inloadMyImage加載圖像文件名及其關聯的備用圖像。
理想情況是DynamicImage的loadMyImage被調用(加載alt圖像)...它反過來調用super.loadMyImage(加載英文圖像)。應該加載兩個圖像文件。
然而,這對圖像是LOADED TWICE ...請參閱下面的跟蹤語句。
我覺得即使我的movieclip實例是DynamicImage ...超級的構造函數先被調用,然後調用DyanmicImage的構造函數!
public class DynamicSingleImage extends Sprite
{
var eLoader:Loader; //for english image
public function DynamicSingleImage()
{
trace("DynamicSingleImage...for: " + this.name);
loadMyImage();
}
public function loadMyImage() :void
{
...
trace("always load ENGLISH file :" + engFilename);
...
}
}
public class DynamicImage extends DynamicSingleImage
{
var aLoader:Loader; //for alternate language image
public function DynamicImage()
{
trace("DynamicImage for: " + this.name);
this.loadMyImage();
}
override public function loadMyImage() :void
{
trace("============= START ========================");
trace("loading images for mc: " + this.name);
...
super.loadMyImage(); //first call the super to load the English version
trace("load image for alternate language..." + altFilename
...
trace("============= END ========================");
}
這是跟蹤輸出:
DynamicSingleImage...for: eel_hotspot_content_mc
============= START ========================
loading images for mc: eel_hotspot_content_mc
always load ENGLISH file :eel_hotspot_content.jpg
load image for alternate language...eel_hotspot_content_alt.jpg
============= END ========================
DynamicImage for: eel_hotspot_content_mc
============= START ========================
loading images for mc: eel_hotspot_content_mc
always load ENGLISH file :eel_hotspot_content.jpg
load image for alternate language...eel_hotspot_content_alt.jpg
對於super construtor總是從子類構造函數中調用的信息+1。 – milesmeow 2012-03-12 21:36:57