topical media & game development

talk show tell print

flex-dragdrop-initiate.mx

flex-dragdrop-initiate.mx [swf] flex


  <?xml version="1.0" encoding="utf-8"?>
  <mx:Application 
          xmlns:mx="http://www.adobe.com/2006/mxml"         
          viewSourceURL="@mx-flex-dragdrop-initiate.html"
          width="600" height="400" 
  >
          <mx:Script>
                  <![CDATA[
                          import mx.managers.DragManager;
                          import mx.core.DragSource;
                          
                          // Embed the various Euro coin images. Images originally 
                          // from Wikipedia (http://en.wikipedia.org/wiki/Euro_coins)
  			[Embed("local/flex/assets/1c.png")]
                          [Bindable]
                          public var OneCent:Class;
                          
                          [Embed("local/flex/assets/2c.png")]
                          [Bindable]
                          public var TwoCents:Class;
                          
                          [Embed("local/flex/assets/5c.png")]
                          [Bindable]
                          public var FiveCents:Class;
                          
                          [Embed("local/flex/assets/10c.png")]
                          [Bindable]
                          public var TenCents:Class;
  
                          private function dragIt(event:MouseEvent, value:uint):void 
                          {
                      // Get the drag initiator component from the event object.
                      var dragInitiator:Image = event.currentTarget as Image;
          
                      // Create a DragSource object.
                      var dragSource:DragSource = new DragSource();
          
                      // Add the data to the object.
                      dragSource.addData(value, 'value');
          
                      // Create a copy of the coin 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. 
                      // For information on this method, see 
                      // the "Initiating the drag" section.
                      DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);
                  }
  
                  ]]>
          </mx:Script>
          
          <mx:HBox>
                  <mx:Image 
                          id="oneCent" source="{OneCent}"
                          mouseMove="dragIt(event, 1);"
                  />
                  <mx:Image 
                          id="twoCents" source="{TwoCents}"
                          mouseMove="dragIt(event, 2);"
                  />
                  <mx:Image 
                          id="fiveCents" source="{FiveCents}"
                          mouseMove="dragIt(event, 5);"
                  />
                  <mx:Image 
                          id="tenCents" source="{TenCents}"
                          mouseMove="dragIt(event, 10);"
                  />                
          </mx:HBox>
          
  </mx:Application>
  


(C) Æliens 27/08/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.