Friday, December 15, 2006

Drag Drop from a Pop-up(Library Module)

Hi folks,
The entire last week i was struggling with the Drag Drop functionality for one of our module..So i wanna post this example for other ppl..I have seen lotsa queries on the same.So here is the example which i had created along with one of my team member.

Library.mxml
------------
<%

%>

import mx.core.IFlexDisplayObject;
import mx.controls.Alert;
import mx.containers.Canvas;
import mx.managers.PopUpManager;
import mx.events.DragEvent;
import mx.managers.DragManager;
import mx.core.DragSource;
import mx.containers.Canvas;
import mx.controls.Image;

public var dragInitiator:Image;
public var ds:DragSource;
public var dragProxy:Image;

public var libPop:*;
public var canTarget:Canvas;
public var imgTarget:Image;

public function openLibrary():void
{
libPop = PopUpManager.createPopUp( this ,CustLib, false );
}

public function dragEnterHandler(event:DragEvent):void
{
DragManager.showFeedback(DragManager.COPY);
canTarget = Canvas(event.currentTarget);
DragManager.acceptDragDrop(canTarget);
}

public function dragDropHandler(event:DragEvent):void
{
var dropTarget:Canvas = Canvas(event.currentTarget);
var imageProxy:Image = new Image();
imageProxy.source = libPop.ImageSelection.dataProvider[libPop.ImageSelection.selectedIndex].icon;

imageProxy.height = dropTarget.height/2;
imageProxy.width = dropTarget.width/2;
imageProxy.x = dropTarget.mouseX-75;
imageProxy.y = dropTarget.mouseY-75;

dropTarget.addChild(imageProxy);
}

public function displayChildren():void
{
Alert.show("Canvas Children-> "+myCan.numChildren.toString() + "\n" + "Pop Children->"+libPop.numChildren.toString());
}

]]>

dragEnter="dragEnterHandler(event);"
dragDrop="dragDropHandler(event);"
backgroundColor="#ffffff"
backgroundAlpha="1.0"
>







CustLib.mxml
-------------



x="{mx.core.Application.application.myCan.x + mx.core.Application.application.myCan.width}"
y="{mx.core.Application.application.myCan.y}"
>

import mx.events.DragEvent;
import mx.collections.*;
import mx.managers.DragManager;
import mx.controls.Alert;
import mx.controls.Image;
import mx.containers.Canvas;


[Bindable]
[Embed(source="assets/AAH.jpg")]
public var phone1:Class;

[Bindable]
[Embed(source="assets/AAV.JPG")]
public var phone2:Class;

[Bindable]
[Embed(source="assets/BLUESUN.JPG")]
public var phone3:Class;

[Bindable]
[Embed(source="assets/10c.png")]
public var phone4:Class;

[Bindable]
[Embed(source="assets/EYE.JPG")]
public var phone5:Class;


private function doDragEnter(event:DragEvent):void
{
var dropTarget:Canvas=Canvas(event.currentTarget);
DragManager.acceptDragDrop(dropTarget);
}

private function doDragDrop(event:DragEvent):void
{
var dropTarget:Canvas=Canvas(event.currentTarget);
var imageProxy:Image = new Image();
imageProxy.source = Image(event.dragSource.dataForFormat('images')).source;

imageProxy.height = dropTarget.height/2;
imageProxy.width = dropTarget.width/2;
imageProxy.x = dropTarget.mouseX-75;
imageProxy.y = dropTarget.mouseY-75;


}



paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10" layout="absolute">
maxColumns="1" rowHeight="125" columnWidth="125" dragEnabled="true" >













Tuesday, December 12, 2006

Flex Archive

Long time i havent posted anything.I m really occupied these days.Lotsa Actionscripting,Flashing,Flexing et al.I am bit occupied these days.Now i am working on Flex with Magnet Technologies Pvt Ltd. I m really thankful to Nirav Mehta and the entire Magnet team for allowing me to show my skills in Flex and Flash.There is lot to learn in Flex/Flash AS3.So trying to get hands on those things.Last week i was having a conversation with my TL and i came up with this idea of archiving whatever we create in Flex.So we decided to address a blog only for our newly created components and scripts and archive all those things at one place.In case if you require anything you can make a request.I will try to make it one for you.But to be honest i m still learning AS 3 so i m not sure that whatever i create will be flawless.And its been only 8 months that I am working on it.I know i have to go a long way.But we guys at Magnet have decided to put our asses on fire and work on these kinda things.So anybody out there wanna contribute to this archive are equally welcomed.Keep Actionscripting !!