2009-02-26 57 views
1

我正在使用HorizontalList組件顯示圖像列表,您可以從另一個組件拖動圖像以加入列表,這一切都正常。Flex/AS3拖放 - 自定義拖放反饋

如果我做list.showDropFeedback(event)我得到的圖像在HorizontalList頂難看的黑條 - 我真正想要的是一條線的形象,在新的人會真正坐下的左/右。

我想我需要定義一個自定義DropFeedback來覆蓋默認值。有誰知道是否有辦法實現這一目標?

謝謝!

回答

3

尤奧可以通過重寫showDropFeedback()方法來克服它。我的代碼如下:

import mx.controls.HorizontalList; 
import mx.controls.listClasses.IListItemRenderer; 
import mx.core.mx_internal; 
import mx.events.DragEvent; 

use namespace mx_internal; 

public class HList extends HorizontalList 
{ 
    public function HList() 
    { 
     super();       
    } 


     override public function showDropFeedback(event:DragEvent):void 
     { 

      super.showDropFeedback(event); 

      dropIndicator.setActualSize(rowHeight - 4, 4); 
      DisplayObject(dropIndicator).rotation = 90; 

     } 



} 
+0

我沒有足夠的代表編輯您的文章,但請注意前兩個導入語句未包含在代碼塊中。你應該解決這個問題。 – 2009-05-06 20:07:23

1

有一個名爲dropIndicatorSkin的樣式屬性,它控制在拖動基於列表的組件時顯示的行的外觀。 從Adobe的文檔:

dropIndicatorSkin

的皮膚使用,以指示所拖動項目被刪除。當ListBase派生的組件是拖放操作中的潛在拖放目標時,調用showDropFeedback()方法將生成此類的一個實例,並將其放置在該項目的itemRenderer之上一個像素,其中如果發生拖放,是丟棄項目後的項目。默認值是mx.controls.listClasses.ListDropIndicator

所有的功能都內置到Horizo​​ntalList中去完成你所要求的功能,但是似乎在Horizo​​ntalList中有一個錯誤,它並沒有將其方向屬性設置爲水平。

所有你需要做的就是把方向=「橫向」在MXML聲明中,就旋轉dropIndicatorSkin 90度,poistion它在項目之間,而不是在他們之上:

<mx:HorizontalList ... direction="horizontal" ... /> 
0

謝謝,這似乎按預期旋轉dropIndicator,但會產生其他非常意外的行爲。列表上的水平滾動條突然消失,並將一個項目拖動到列表中,使其直接跳到最後....感覺就像我幾乎在那裏,但不完全!

我的AS3代碼....

// in constructor... (extends HorizontalList) 
this.direction = "horizontal"; 

this.addEventListener(DragEvent.DRAG_ENTER, onDragEnter); 
this.addEventListener(DragEvent.DRAG_OVER, onDragOver); 
this.addEventListener(DragEvent.DRAG_EXIT, onDragExit); 
this.addEventListener(DragEvent.DRAG_DROP, onDragDrop); 

private function onDragEnter(event:DragEvent):void { 
    event.preventDefault(); 
    if (event.dragSource.hasFormat("treeItems") || event.dragSource.hasFormat("items")) { 
     DragManager.acceptDragDrop(event.target as UIComponent); 
    } 
    this.showDropFeedback(event); 
} 

public function onDragOver(event:DragEvent):void { 
    event.preventDefault(); 
    this.showDropFeedback(event); 
} 

public function onDragExit(event:DragEvent):void { 
    event.preventDefault(); 
    this.showDropFeedback(event); 
} 

private function onDragDrop(event:DragEvent):void { 
    event.preventDefault(); 
    this.hideDropFeedback(event); 
    //.... 
} 
+0

您是否有特別的原因要求您自己調用preventDefault()並執行showDropFeedback()和hideDropFeedback(),或者您是否試圖手動繪製指示符? – 2009-02-27 17:16:21

+0

刪除它們似乎有一點幫助。但是現在我的Horizo​​ntalList似乎更像一個TileList,即。 3行3而不是9行1行 - 到達那裏,慢慢地...... – adam 2009-03-04 08:57:37

2

我解決了這個最終被添加在我的申請方式如下..

HorizontalList { 
dropIndicatorSkin: ClassReference("com.package.HorizontalListDropIndicator"); 
} 

和創建我的自定義皮膚..

package com.package { 

import flash.display.Graphics; 
import mx.skins.ProgrammaticSkin; 

public class HorizontalListDropIndicator extends ProgrammaticSkin { 

    public function HorizontalListDropIndicator() { 
    super(); 
    } 

    override protected function updateDisplayList(w:Number, h:Number):void { 
    super.updateDisplayList(w, h); 

    var g:Graphics = graphics; 

    g.clear(); 
    g.lineStyle(2, 0xFF0000); 

    g.moveTo(0, 0); 
    g.lineTo(0, 250); 

    } 
} 
} 
2

看起來這是在Flex框架的錯誤:

Flex Builder 3/sdks/3.3.0/frameworks/projects/framework/src/mx/controls/HorizontalList.as(線95-105)

public function HorizontalList() 
{ 
    super(); 

    _horizontalScrollPolicy = ScrollPolicy.AUTO; 
    _verticalScrollPolicy = ScrollPolicy.OFF; 

    direction = TileBaseDirection.VERTICAL; 
    maxRows = 1; 
    defaultRowCount = 1; 
} 

注意,構造函數Horizo​​ntalList將是初始化方向值爲垂直

一個快速簡便的解決辦法是簡單地在你的MXML指定direction="horizontal"

<mx:HorizontalList id="fooLst" direction="horizontal" dataProvider="{foo}" /> 

如果這個bug尚未固定的(並等待下一個版本),我會感到很驚訝,但如果沒有記錄,我會檢查Flex SDK bug database並提交報告。