[問題] 關於 Sprite 與記憶體清除的問題
想請問一下版上個位高手一些關於 Function 中物件的問題
還有 Sprite 的問題
我現在在練習寫遊戲!!
當中會有一個商店 ~
假設商店當中有十個商品
(因為商品當中有圖與資料所以我用Sprite包裝)
但是畫面中只能顯示兩個
所以我是寫了一個 Function ListShow
去創造商品資訊並且傳回到預設的 Sprite
同時這 function 還要負責刷新商品資訊
(當使用者呼叫下一頁的資訊的時候)
程式的片段在下面
我的問題是 在 ListShow 關於 renew 的程式碼似乎沒有作用?
如果我用 Container1 = ListShow(Container1, SpriteIndex, 0);
由於資料會寫回來原本的容器 畫面上的東西會更新
如果我用 ListShow(Container1, SpriteIndex, 1);
Container1 的話面不會消失 所以表示我 renew 的部份沒效?
那我到底要怎麼寫 才可以將 Container1 從畫面中清除 同時從記憶體中清除
還請版上先進指導 ~
var Container1
function CallShop(me:MouseEvent) {
// 創造商品資訊的 Function ListShow
Container1 = ListShow(Container1, SpriteIndex, 0);
}
function ListShow(Bcontainer:Sprite, Sindex:int, renew:int = 0) {
if (renew == 1) {
Bcontainer.removeEventListener(MouseEvent.CLICK, FunctionX);
stage.removeChild(Bcontainer);
Bcontainer = null;
}
Bcontainer = new Sprite;
Bcontainer.addEventListener(MouseEvent.CLICK, FunctionX);
stage.addChild(Bcontainer);
stage.setChildIndex(RL_btn, stage.numChildren -1);
//trace(Bcontainer.name);
return Bcontainer;
}
--
要看著前方前進
要是往旁邊或是往下方看的話
便會忌妒... 害怕...
看著前方的人
注視著群星的人...
STARGAZER 觀星者...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.43.122.216
推
03/30 12:05, , 1F
03/30 12:05, 1F
→
03/30 12:05, , 2F
03/30 12:05, 2F
→
03/30 12:06, , 3F
03/30 12:06, 3F
→
03/30 12:25, , 4F
03/30 12:25, 4F
→
03/30 12:30, , 5F
03/30 12:30, 5F
→
03/30 12:30, , 6F
03/30 12:30, 6F
推
03/30 13:17, , 7F
03/30 13:17, 7F
→
03/30 13:59, , 8F
03/30 13:59, 8F
→
03/30 14:00, , 9F
03/30 14:00, 9F
→
03/30 14:00, , 10F
03/30 14:00, 10F
推
03/30 14:42, , 11F
03/30 14:42, 11F
→
03/30 14:44, , 12F
03/30 14:44, 12F
→
03/30 14:44, , 13F
03/30 14:44, 13F
用修文來回答 ~
我做 removeChild 不會有錯誤訊息!!
我有想過是不是 Function 內的 Bcontainer:Sprite
只是繼承了外部 conatiner1 的一切的副本
可是我可以取消監聽 卻不能移除他 這點好奇怪喔...
※ 編輯: STARGAZERs 來自: 114.43.122.216 (03/30 16:23)
推
03/30 16:22, , 14F
03/30 16:22, 14F
→
03/30 16:23, , 15F
03/30 16:23, 15F
→
03/30 16:26, , 16F
03/30 16:26, 16F
→
03/30 16:26, , 17F
03/30 16:26, 17F
→
03/30 17:06, , 18F
03/30 17:06, 18F
→
03/30 17:08, , 19F
03/30 17:08, 19F
→
03/30 17:10, , 20F
03/30 17:10, 20F
→
03/30 17:10, , 21F
03/30 17:10, 21F
Flash 近期熱門文章
PTT數位生活區 即時熱門文章