<< Chapter < Page Chapter >> Page >

The dragenter event handler.

private function enterHandler(event:DragEvent):void{ if (event.dragSource.hasFormat("imageObject")){DragManager.acceptDragDrop( Canvas(event.currentTarget));} //end if } //end enterHandler

Confirm the correct format string

The code in Listing 13 checks to confirm that the format string in the DragSource object matches "imageObject" (see Listing 11). If so, it calls the static acceptDragDrop method on the DragManager class, passing a reference to itself as a parameter in the method call.

Accept the dragged object

The call to the acceptDragDrop method notifies the DragManager that the Canvas object is willing to accept the contents of the DragSource object being dropped onto itself.

Beginning of the dragDrop event handler

The dragDrop event handler was registered on the Canvas object in Listing 8. This method is executed after the Canvas object accepts the drag and the user releases the mouse button while the drag proxy isover the Canvas .

Correct the drop position for the image

The code in Listing 14 uses the current location of the mouse pointer along with the values stored in localX and localY to compute the new location for the upper-left corner of the image when it is dropped on the canvas.

(Recall that localX and localY contain the coordinates of the mouse pointer relative to the upper-left corner of the image when the mouseDown event was dispatched by the image and the drag and drop operation began.)

I explained the need for this position adjustment earlier .

Beginning of the dragdrop event handler.

private function dropHandler(event:DragEvent):void{ var cornerX:Number = (Canvas(event.currentTarget). mouseX) - localX;var cornerY:Number = (Canvas(event.currentTarget). mouseY) - localY;

Do the drop

Listing 15 checks to confirm that the location at which the upper-left corner of the image will be placed is within the bounds of the canvas on the left sideand the top. If so, it sets the coordinates of the Image object that dispatched the original mouseDown event to the coordinates that were computed in Listing 14. This causes that Image object to move to the new position on the Canvas object.

Do the drop.

if((cornerX>0.0)&&(cornerY>0.0)){ Image(event.dragInitiator).x = cornerX;Image(event.dragInitiator).y = cornerY } //end if} //end dropHandler //--------------------------------------------------//} //end class} //end package

The end of the program

Listing 15 also signals the end of the dragDrop event handler, the end of the Driver class, and the end of the program.

Run the program

I encourage you to run this program from the web. Then copy the code from Listing 16 and Listing 17. Use that code to create a Flex project.Compile and run the project. Experiment with the code, making changes, and observing the results of your changes. Make certain that you can explainwhy your changes behave as they do.

Questions & Answers

what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with actionscript. OpenStax CNX. Jun 04, 2010 Download for free at http://cnx.org/content/col11202/1.19
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?

Ask