posts - 325,  comments - 25,  trackbacks - 0

          拖放效果:
          a) List組件有內(nèi)置的拖放功能,只要設(shè)置dragEnabled="true",再在接受數(shù)據(jù)的List組件中設(shè)置dropEnabled="true"
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application layout="absolute"
            xmlns:mx="http://www.adobe.com/2006/mxml"
            width="450" height="350"
            creationComplete="initApp();"
            backgroundColor="#FFFFFF">
            <mx:Script>
              <![CDATA[
              // setup 3 dataProviders, 2 empty
              private function initApp():void{
                words.dataProvider = ['Water', 'Agua', 'Car', 'Coche', 'House', 'Casa', 'Book', 'Libro', 'Music', 'Música', 'Sandwich', 'Bocadillo'];       
                english.dataProvider = [];
                spanish.dataProvider = [];
              }
              ]]>
            </mx:Script>
            <mx:Panel title="Sort Words By Language" layout="absolute" x="0" y="0" width="450" height="350">
              <mx:Label text="Drag to the Correct Language" x="7" y="3"/>
              <mx:List id="words" width="200" height="275"
                allowMultipleSelection="true"               
                dragEnabled="true" y="25" x="7"/>
              <mx:Label text="English" y="6" x="223"/>
              <mx:List id="english" width="200" height="120"
                dropEnabled="true" y="25" x="223"/>
              <mx:Label text="Spanish" x="223" y="150"/>
              <mx:List id="spanish" width="200" height="120"
                dropEnabled="true" y="177" x="223"/>
            </mx:Panel>
          </mx:Application>
          b) 其它組件的拖放支持
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="450" height="300"
            creationComplete="initApp()" paddingLeft="0" paddingTop="0">
            <mx:Script>
              <![CDATA[
              import mx.collections.ArrayCollection;
              import mx.events.DragEvent;
              import mx.managers.DragManager;
              import mx.core.DragSource;
              [Bindable]
              public var total:Number = 0;
              [Bindable]
              public var cartContents:ArrayCollection;
              private function initApp():void{
               this.cartContents = new ArrayCollection();
              }
              private function dragIt(event:MouseEvent, name:String, price:Number):void {
                // The currentTarget specifies the component initiating the drag.
                var dragInitiator:Image = event.currentTarget as Image;
                // Create a new  DragSource object containing the data being dragged
                var dragSource:DragSource = new DragSource();
                // Add the data to the object.
                dragSource.addData(name, 'name');
                dragSource.addData(price, 'price');
                // Create a copy of the image to use as a drag proxy.
                var dragProxy:Image = new Image();
                dragProxy.source = event.currentTarget.source;
                // Call the DragManager doDrag() method to start the drag.
                DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);
              }
              // Called if the user drags a drag proxy onto the drop target.
              private function dragEnterHandler(event:DragEvent):void {
                // Get the drop target component from the event object.
                var dropTarget:DataGrid=event.currentTarget as DataGrid;
                // Accept the drag only if the object contains the correct data
                if (event.dragSource.hasFormat('name') && event.dragSource.hasFormat('price')){
                  // Accept the drop.
                  DragManager.acceptDragDrop(dropTarget);
                }
              }
              // Called if used drops the object over the target and the target accepts the object
              private function dragDropHandler(event:DragEvent):void {
                // Set the data from the dragSource to local vars.
                var name:String  = String(event.dragSource.dataForFormat('name')) ;
                var price:Number  = Number(event.dragSource.dataForFormat('price')) ;
                this.cartContents.addItem({name:String(event.dragSource.dataForFormat('name')),price:Number(event.dragSource.dataForFormat('price'))});
                // Add the price to the total
                total += price;
              }
              ]]>
            </mx:Script>
            <mx:Canvas width="100%" height="100%" backgroundColor="#FFFFFF">
            <mx:Image source="yankee.jpg" mouseMove="dragIt(event, 'Yankee hat', 19.99);" x="23" y="35"/>
            <mx:Label text="$ 19.99"  x="53" y="215"/>
            <mx:Image source="mets.jpg" mouseMove="dragIt(event, 'Met hat', 19.99);" x="23" y="135"/>
            <mx:Label text="$ 19.99"  x="53" y="109"/>
            <mx:Label text="Shopping Cart"  x="226" y="28" fontWeight="bold"/>
            <mx:DataGrid id="cart" dataProvider="{cartContents}" dragEnter="dragEnterHandler(event);" dragDrop="dragDropHandler(event);" x="175" y="50" height="165">
              <mx:columns>
                <mx:DataGridColumn dataField="name" headerText="Name" />
                <mx:DataGridColumn dataField="price" headerText="Price" />
              </mx:columns>
            </mx:DataGrid>
            <mx:Label text="Total: $ {total}"  x="215" y="222"/>   
            <mx:Label x="93.5" y="2" text="Drag a product into the shopping cart"/>
            <mx:HRule x="5" y="20" width="390"/>
            </mx:Canvas>
          </mx:Application>

          posted on 2011-03-15 16:10 長春語林科技 閱讀(218) 評論(0)  編輯  收藏 所屬分類: flex
          <2011年3月>
          272812345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

           

          長春語林科技歡迎您!

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 隆林| 巴南区| 溆浦县| 沙坪坝区| 封开县| 夹江县| 安乡县| 裕民县| 宝兴县| 遵义市| 枝江市| 德州市| 金溪县| 河曲县| 淳化县| 政和县| 丁青县| 铜山县| 白玉县| 和顺县| 来宾市| 赤峰市| 简阳市| 崇礼县| 山东省| 乌鲁木齐市| 通城县| 二手房| 锡林浩特市| 静宁县| 册亨县| 贡嘎县| 望谟县| 玉林市| 临朐县| 临汾市| 中卫市| 金乡县| 如东县| 本溪| 石渠县|