he cogido un ejemplo de Flex+AS de Internet y lo estoy adaptando, pero no me sale cuando intento hacer un "removeEventListener" de unas imágenes que se les puede hacer drag/drop en el evento MOUSE_MOVE....
alguien me ayuda por favor?
Gracias.
Ahí va el código.....
Código Flex :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="complete()">
<mx:Script>
<![CDATA[
import mx.core.FlexSprite;
import mx.core.UIComponent;
import mx.controls.Image;
import mx.containers.Canvas;
import mx.core.DragSource;
import myPackage.GameDTO;
import mx.managers.DragManager;
import mx.events.DragEvent;
import mx.collections.ArrayCollection;
[Embed("images/dibujo1.JPG")]
private var bioshock_icon:Class;
[Embed("images/dibujo2.JPG")]
private var crysis_icon:Class;
[Embed("images/dibujo3.JPG")]
private var halo_icon:Class;
[Embed("images/dibujo4.JPG")]
private var neverwinter_icon:Class;
[Embed("images/dibujo5.JPG")]
private var wow_icon:Class;
[Bindable]
private var flag:Boolean = true;
[Bindable]
private var cartContents:ArrayCollection = new ArrayCollection();
private function complete():void
{
do1(false);
}
private function dragDrop(event:DragEvent):void
{
var img:Image = event.dragSource.dataForFormat('img') as Image;
addToCart(img);
}
private function addToCart(img:Image):void
{
var bfind:Boolean = false;
for each (var game:GameDTO in cartContents)
{
if (game.name == img.name)
{
game.amount++;
bfind = true;
break;
}
}
if (!bfind)
{
game = new GameDTO();
game.name = img.name;
game.amount = 1;
cartContents.addItem(game);
}
dg.dataProvider.refresh();
}
private function dragAccept(event:DragEvent):void
{
var dropTarget:Canvas = event.currentTarget as Canvas;
DragManager.acceptDragDrop(dropTarget);
}
private function doDrag(event:MouseEvent):void
{
/*if (!flag)
return;*/
var img:Image = event.currentTarget as Image;
var dragImg:Image = new Image();
dragImg.source = img.source;
var dsource:DragSource = new DragSource();
dsource.addData(img, 'img');
DragManager.doDrag(img, dsource, event, dragImg);
}
private function do1(flag:Boolean):void
{
//this.flag = flag;
for each (var element:UIComponent in hbox1.getChildren())
{
if (element is Image)
{
var img:Image = element as Image;
var bMouseEvent:Boolean = img.hasEventListener(MouseEvent.MOUSE_MOVE);
if (flag && !bMouseEvent)
{
img.addEventListener(MouseEvent.MOUSE_MOVE, doDrag, false, 0);
}
else if (!flag && bMouseEvent)
{
img.removeEventListener(MouseEvent.MOUSE_MOVE, doDrag, true);
}
}
}
}
]]>
</mx:Script>
<mx:VBox id="vbox1" height="100%" width="100%">
<mx:Label text="Games" width="118" height="42" fontSize="28" color="#818181"/>
<mx:HBox id="hbox1">
<mx:Image name="Bioshock" source="{bioshock_icon}"
/>
<mx:Image name="Crysis" source="{crysis_icon}"
/>
<mx:Image name="Halo" source="{halo_icon}"
/>
<mx:Image name="World of Warcraft" source="{wow_icon}"
/>
</mx:HBox>
<mx:Canvas
borderStyle="solid" backgroundColor="#12976A"
width="201" height="200"
dragEnter="dragAccept(event)" dragDrop="dragDrop(event)">
<mx:Label text="Basket" width="118" height="42"
fontSize="28" color="#FFFFFF"/>
</mx:Canvas>
<mx:DataGrid id="dg" dataProvider="{cartContents}"
width="201" height="100">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="name"/>
<mx:DataGridColumn headerText="Quantity" dataField="amount" width="65"/>
</mx:columns>
</mx:DataGrid>
<mx:Button id="btn1" label="Habilitar drag" click="do1(true)"/>
<mx:Button id="btn2" label="Deshabilitar drag" click="do1(false)"/>
</mx:VBox>
</mx:Application>
