or u can u this type,

if (event.dragSource.hasFormat("img")) {
            var draggedImage:Image =
            event.dragSource.dataForFormat('img') as Image;
             var dropCanvas:Canvas = event.currentTarget as Canvas;

            // Since this is a copy, create a new object to
            // add to the drop target.
            var newImage:Image=new Image();
            newImage.source=draggedImage.source;
            newImage.id = draggedImage.id;
             newImage.x = dropCanvas.mouseX-newImage.width/2;
            newImage.y = dropCanvas.mouseY-35;
             dropCanvas.addChild(newImage);

Thats it.
On Fri, Apr 11, 2008 at 11:51 AM, anuppc <[EMAIL PROTECTED]> wrote:

>   Daniel,
>
> I tried this.
>
> var draggedImage:Image = event.draggedItem as Image;
>
> var dropCanvas:Canvas = event.currentTarget as Canvas;
> var bmpData:BitmapData = Bitmap(draggedImage.content).bitmapData;
> var bitmap:Bitmap = new Bitmap(bmpData);
> var newImage:Image = new Image();
> newImage.source = bitmap;
> newImage.x = dropCanvas.mouseX;
> newImage.y = dropCanvas.mouseY;
> dropCanvas.addChild(newImage);
>
> I get this error:
>
> TypeError: Error #1009: Cannot access a property or method of a null
> object reference.
>
> The error trace points to "draggedImage.content". Looks like
> draggedImage is null.
>
> I was trying out a few other things to see what formats are available
> from DragSource
>
> var ds:DragSource = event.dragSource;
> var formatArray:Array = ds.formats;
> for (var i:String in formatArray)
> {
> Alert.show(formatArray[i]);
> }
>
> The Alert shows "items" as the value in the formatArray.
>
> Not sure how to get hold of the Image. The source as i said was an
> mx:Object array which has icon attribute using a embed image.
>
> Let me know if i can try anything else. Thanks
>
> --- In [email protected] <flexcoders%40yahoogroups.com>, "Daniel
> Gold" <[EMAIL PROTECTED]> wrote:
> >
> > Give this a shot:
> >
> > var bmpData:BitmapData =
> > Bitmap(draggedImage.content).bitmapData;
> > var bitmap:Bitmap = new Bitmap(bmpData);
> > var newImage:Image = new Image();
> > newImage.source = bitmap;
> >
> > that should give you a newImage object that reuses the same bitmap
> data from
> > the original image
> >
> > On Thu, Apr 10, 2008 at 3:33 AM, anuppc <[EMAIL PROTECTED]> wrote:
> >
> > > Daniel,
> > >
> > > Yes the original image is embedded.
> > >
> > > Can you show some example on getting the bitmapdata of the draggedItem
> > > out of the event? I presume that is what you are suggesting.
> > >
> > > Thanks
> > > Anup
> > >
> > >
> > > --- In [email protected] 
> > > <flexcoders%40yahoogroups.com><flexcoders%
> 40yahoogroups.com>,
>
> "Daniel
> > > Gold" <danielggold@> wrote:
> > > >
> > > > is the original image embedded? instead of setting the source of the
> > > > draggedImage you may want to get the bitmap data out of the original
> > > image
> > > > and reuse it for efficiency.
> > > >
> > > > On Wed, Apr 9, 2008 at 1:47 PM, anuppc <anuppc@> wrote:
> > > >
> > > > > have a drag and drop issue.
> > > > >
> > > > > Drag Source is
> > > > >
> > > > > <mx:Panel x="48" y="125" width="800" height="600"
> layout="absolute"
> > > > > title="Drag onto Tree">
> > > > >
> > > > > <mx:Accordion id="accordion" width="200" height="450" left="10"
> > > > > top="10" bottom="10">
> > > > > <!-- Define each panel using a VBox container. -->
> > > > > <mx:VBox label="Events" >
> > > > > <mx:List width="200" height="450" right="10" bottom="10"
> > > id="eventlist"
> > > > > allowMultipleSelection="true"
> > > > > dataProvider="{events}"
> > > > > dragEnabled="true"
> > > > > dragMoveEnabled="true"
> > > > > >
> > > > > </mx:List>
> > > > > </mx:VBox> .......
> > > > >
> > > > > The DataProvider {events} is an array of Objects
> > > > >
> > > > > <mx:Array id="events">
> > > > > <mx:Object icon="startIcon" width="20" height="20"
> label="Start" />
> > > > > <mx:Object icon="endIcon" width="30%" height="30%" label="End"/>
> > > > > <mx:Object icon="intermediateIcon" width="30%" height="30%"
> > > > > label="Intermediate"/>
> > > > > <mx:Object icon="msgStartIcon" width="30%" height="30%"
> > > label="Message"/>
> > > > > <mx:Object icon="timerStartIcon" width="30%" height="30%"
> > > label="Timer"/>
> > > > > </mx:Array>
> > > > >
> > > > > Now the Target for drop is a Canvas
> > > > >
> > > > > <mx:Canvas borderStyle="inset" height="420" width="520" left="250"
> > > > > top="10" bottom="10"
> > > > > dragEnter="onDragEnter(event)"
> > > > > dragDrop="onDragDrop(event)"
> > > > > dragOver="onDragOver(event)" >
> > > > > <mx:Panel id="lanes" width="100%" height="100%"/>
> > > > > </mx:Canvas>
> > > > >
> > > > > Now the dragDrop handler is as follows :
> > > > >
> > > > > private function onDragDrop( event:DragEvent ) : void
> > > > >
> > > > > {
> > > > > var ds:DragSource = event.dragSource;
> > > > > trace(ds);
> > > > >
> > > > > Alert.show("onDragDrop Clicked!");
> > > > > var formatArray:Array = ds.formats;
> > > > > for (var i:String in formatArray)
> > > > > {
> > > > > Alert.show(formatArray);
> > > > > }
> > > > > var draggedImage:Image = event.dragInitiator as Image;
> > > > > var dropCanvas:Canvas = event.currentTarget as Canvas;
> > > > > var newImage:Image=new Image();
> > > > >
> > > > > newImage.source = ds;
> > > > > newImage.x = dropCanvas.mouseX;
> > > > > newImage.y = dropCanvas.mouseY;
> > > > > dropCanvas.addChild(newImage);
> > > > >
> > > > > }
> > > > >
> > > > > Problem is Image does not get displayed. It shows a missing
> image icon
> > > > > on the target Canvas.
> > > > >
> > > > >
> > > > >
> > > >
> > >
> > >
> > >
> >
>
>  
>



-- 
Thanks & Regards
Swaminathan. M

Reply via email to