<< Chapter < Page Chapter >> Page >

Resources

I will publish a list containing links to ActionScript resources as a separate document. Search for ActionScriptResources in the Connexions search box.

Complete program listings

Complete listings for the MXML and ActionScript code discussed in this lesson are provided in Listing 16 and Listing 17 below.

The mxml file for draganddrop01.

<?xml version="1.0" encoding="utf-8"?><!--DragAndDrop01 --><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"xmlns:cc="CustomClasses.*"><cc:Driver/></mx:Application>
Listing

The actionscript file for draganddrop01.

/*DragAndDrop01 Illustrates the fundamentals of drag and drop inActionScript 3. Places three images in a Canvas object:0 - space.jpg - largest 1 - snowscene.jpg - midsize2 - frog.jpg - smallest Sets the z-axis indices as shown above. This causes thespace image to be in the back, the frog image to be in the front, and the snowscene image to be in the middle.Any of the images can be dragged and dropped anywhere within the canvas so long as the mouse pointer doesn'tleave the canvas. However, If the edge of the dragged image goes outside the left edge or the top of the canvas,the drag and drop operation is aborted. If the dragged image goes outside the right side or the bottom of thecanvas, scroll bars automatically appear on the canvas. The size of the canvas is based on the size of the spaceimage so that other images can be substituted for mine when the program is recompiled so long as the file namesand paths are the same. *********************************************************/package CustomClasses{ import flash.events.MouseEvent;import mx.containers.Canvas;import mx.controls.Image; import mx.core.DragSource;import mx.events.DragEvent; import mx.events.FlexEvent;import mx.managers.DragManager; //====================================================//public class Driver extends Canvas {private var imageA:Image = new Image(); private var imageB:Image = new Image();private var imageC:Image = new Image(); private var localX:Number;private var localY:Number;public function Driver(){//constructor //Make the Canvas visible.setStyle("backgroundColor",0x00FFFF); setStyle("backgroundAlpha",1.0);//Embed the image files in the SWF file. [Embed("snowscene.jpg")]var imgA:Class;[Embed("space.jpg")] var imgB:Class;[Embed("frog.jpg")]var imgC:Class;//Load the images from the embedded image files // into the Image objects.imageA.load(imgA); imageB.load(imgB);imageC.load(imgC);// Set the z-axes indices such that the frog is // in front, the snowscene is in the middle and the// space image is at the back. addChildAt(imageB,0);//set index to 0addChildAt(imageA,1);//set index to 1 addChildAt(imageC,2);//set index to 2//Register an event handler that will be executed // whcn the canvas and its children are fully// constructed. this.addEventListener(FlexEvent.CREATION_COMPLETE,completeHandler); } //end constructor//--------------------------------------------------// //This handler method is executed when the Canvas and// its children have been fully created. private function completeHandler(event:mx.events.FlexEvent):void{ //Set the width and height of the canvas based on// the dimensions of imageB. this.width = 1.3*imageB.width;this.height = 1.3*imageB.height;//Register event listeners to support drag and drop // operations on all three images with the canvas// as the drag target. imageA.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler); imageB.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler); imageC.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);this.addEventListener(DragEvent.DRAG_DROP, dropHandler);this.addEventListener(DragEvent.DRAG_ENTER, enterHandler);} //end completeHandler //--------------------------------------------------//// This event handler initiates the drag-and-drop \// operation for the image that dispatches the // mouseDown event.private function mouseDownHandler( event:MouseEvent):void{//Save the location of the mouse within the image // being dragged. This information will be used// later to properly position the dropped image in// the drop target. this.localX = event.localX;this.localY = event.localY; //Get the drag initiator component from the event// object and cast it to the correct type. var dragInitiator:Image = Image(event.currentTarget); //Add the image being dragged to a DragSource// object and define an identifier as a string. var dragSource:DragSource = new DragSource();dragSource.addData(dragInitiator,"imageObject");//Call the static doDrag method on the DragManager // class to manage the overall drag and drop// operation. DragManager.doDrag(dragInitiator,dragSource,event);}//end mouseDownHandler //--------------------------------------------------////This dragEnter event handler causes the canvas to// be a suitable drop target. private function enterHandler(event:DragEvent):void{if (event.dragSource.hasFormat("imageObject")){ DragManager.acceptDragDrop(Canvas(event.currentTarget)); } //end if} //end enterHandler //--------------------------------------------------////Execute the dragDrop event handler to drop the image// in its new location. Compensate for the fact that // the mouse pointer is not at the upper-left corner// of the image. Also don't allow the image to be // dragged off the left side of the canvas or off the// top of the canvas. private function dropHandler(event:DragEvent):void{//Compute the position of the upper-left corner of// the dropped image. var cornerX:Number = (Canvas(event.currentTarget).mouseX) - localX; var cornerY:Number = (Canvas(event.currentTarget).mouseY) - localY; 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

Miscellaneous

This section contains a variety of miscellaneous materials.

Housekeeping material
  • Module name: Drag and Drop Basics
  • Files:
    • ActionScript0140\ActionScript0140.htm
    • ActionScript0140\Connexions\ActionScriptXhtml0140.htm
PDF disclaimer: Although the Connexions site makes it possible for you to download a PDF file for thismodule at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should beaware that some of the HTML elements in this module may not translate well into PDF.

-end-

Questions & Answers

Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
Maciej
characteristics of micro business
Abigail
for teaching engĺish at school how nano technology help us
Anassong
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
SUYASH Reply
for screen printed electrodes ?
SUYASH
What is lattice structure?
s. Reply
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
Sanket Reply
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





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