2011-08-01 48 views
0

我正在發佈我正在使用的TileList的示例項目渲染器。我把它分解成一個非常基本的渲染器。
這是我運行它時得到的痕跡。
1)createChildren被稱爲
2)的commitProperties被稱爲
3)removeFromStage被稱爲
爲什麼項目渲染器調用REMOVED_FROM_STAGE被調用

我不知道爲什麼removeFromStage獲取調用,但顯然是在尋找後ListBase刪除它由於某種原因。
我真正想做的最終結果是當它從列表中滾動時停止加載圖像,顯然,我無法使用REMOVED_FROM_STAGE事件,因爲在列表初始化過程中會觸發此事件。
之所以這樣做是因爲當我在列表中有幾百個項目時,每個項目最多可以有9個圖像。
當用戶滾動到3/4的方式時,會有很長的延遲,直到縮略圖趕上加載。
我希望REMOVED_FROM_STAGE可以讓我清空image.source屬性或其他東西,但這是做不到的。

從技術上講,據我所知,渲染器從不移動位置的數據和內容的移動。

所以我想我真正要問的是有沒有一種方法來優化代碼,我可以停止圖像加載或任何其他想法,使滾動更有效?

<?xml version="1.0" encoding="utf-8"?> 
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" > 
    <mx:Script> 
    <![CDATA[ 
     import mx.controls.Image; 

     override public function set data(val:Object):void{ 
     super.data = val; 
     if(!this.thumbnailContainer){ 
      return; 
     } 
     if(!val){ 
      return; 
     } 

     if(this.data.images.length != this.thumbnailContainer.numChildren){ 
      this.createChildren(); 
     } 
     } 
     override protected function createChildren():void{ 
     super.createChildren() 
     if(this.data == null){ 
      return; 
     } 
     for(var i:int = 0; i < this.data.images.length;i++){ 
      var thumbnail:Image = new Image(); 
      thumbnail.addEventListener(Event.COMPLETE, onLoad); 
      thumbnail.addEventListener(Event.REMOVED_FROM_STAGE, removeFromStage); 
      var p:Panel = new Panel(); 
      p.addChild(thumbnail) 
      p.height = 120 
      p.verticalScrollPolicy = 'off'; 
      p.horizontalScrollPolicy = 'off'; 
      thumbnailContainer.addChild(p) 
     } 
     } 

     override protected function commitProperties():void{ 
     super.commitProperties(); 
     for(var i:int = 0 ;i<this.data.images.length;i++){ 
      var p:Panel = (this.thumbnailContainer.getChildAt(i) as Panel) 
      var img:Image = (p.getChildAt(0) as Image) 
      img.source = this.data.images[i].src 
     } 
     } 

     private function removeFromStage(e:Event):void{ 
     trace('removeFromStage') 
     } 

     private function onLoad(e:Event):void{ 
     trace('onLoad') 
     var img:Image = e.currentTarget as Image; 
     var scale:Number = (img.parent.height - 50)/img.contentHeight; 
     img.scaleX = scale; 
     img.scaleY = scale; 
     } 
    ]]> 
    </mx:Script> 

<mx:HBox id="thumbnailContainer" /> 

回答

0

我知道,Flex開始顯示滾動條時,從列表中移除(並立即讀取)列表組件的所有項呈示器。我在一年前遇到過這個問題。

+0

那麼你的工作是什麼? –

+0

哈哈!我完全跳過了Flex,並開發了自己的列表組件。 –

+0

在這聽起來好像很有趣。 –

0

我對你的itemrenderer中發生了什麼有一些保留。在生命週期實現方面,我是一名新手,但我不擔心createChildren()函數期間的數據,我會在set數據函數中處理這些數據。

override public function set data(value:Object):void 

你似乎也在劇烈地處理你的渲染器中的一些mx:Image。如果我有一個帶有圖像的渲染器,那麼我將圖像製作爲mxml組件(如果渲染器位於mxml中),並通過我重寫的設置數據函數操作源。

我認爲你的一些問題可能是由於你的生命週期實現,與其他組件相比,它對itemrenderer的寬容要小得多,因爲itemrenderer被回收了。

我再次查看了你的代碼,好像你在你的itemrenderer列表中有某種圖像列表,你有沒有考慮過使用TileList? 你說你的

+0

嗯,我需要知道每個項目中有多少圖像,因爲它們可以改變每個項目在圖像數量上的動態。我試圖避免發佈該代碼,因爲它與此問題無關。是的,這是一個TileList組件的渲染器。 –

+0

嗯,我注意到我發佈的簡化代碼並沒有真正傳達我所做的一切,所以我增加了一些。 –

相關問題