Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player


Summary:

Origin Code in Actionscript 3 in Flash

    ●   Copy the code below and paste it. This allows Flash to remember where the item started and that's where the reset button puts it back.


Learn About:

Actionscript 3 Movie Clips Keyframes Actions Panel

  •   This is the 3rd tutorial in the Drag and Drop Project.

1 - Beginning Code    2 - Draggable Items    3 - Origin Code  4 - Reset Button    5 - Target Dropzone     6 - Sound  


Other People's Work:

Here are examples of work inspired by this tutorial.

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

Step #1: Draggable Item in Flash ~

Hopefully you've done this tutorial first.


Click on your Actions and Labels keyframe again keyframe actions

… then hit Alt (⌥)alt option key F9 f9 - and open the Actions panel.

this is the code


Step #2: Add some Space ~

Go all the way to the top and hit Enter several times to clear some space up top …

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player


Step #3: Copy the Code ~

Copy this code …

      
	var orig1X:Number=item1_mc.x; 
	var orig1Y:Number=item1_mc.y;
	var orig2X:Number=item2_mc.x;
	var orig2Y:Number=item2_mc.y;
	var orig3X:Number=item3_mc.x;
	var orig3Y:Number=item3_mc.y; 
	var orig4X:Number=item4_mc.x; 
	var orig4Y:Number=item4_mc.y;
	var orig5X:Number=item5_mc.x;
	var orig5Y:Number=item5_mc.y;
	var orig6X:Number=item6_mc.x;
	var orig6Y:Number=item6_mc.y; 
	var orig7X:Number=item7_mc.x;
	var orig7Y:Number=item7_mc.y;
      

Paste it at the top …

var codes

Again, if you've got only 3 draggable objects, you will need to remove EVERYTHING referencing item4_mc, item5_mc, item6_mc and item7_mc

If you've got MORE than 7 items, you will have to add those accordingly.


Step #4: What's Happening?

This code remembers the starting locations of each draggable object - so when you hit the reset button they all go back to their original positions.

Just must make sure you have 2 lines of code for each object - no more - no less.

seven draggable objets

Again, if you've got only 3 draggable objects, you will need to remove EVERYTHING referencing item4_mc, item5_mc, item6_mc and item7_mc

If you've got MORE than 7 items, you will have to add those accordingly.


Step #5: Scroll to the Bottom of your Code ~

Now scroll down to the bottom of your code …

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

… and click somewhere below the last line of the code.

bottom of code


Step #6: Copy this Code ~

Copy and Paste this code:

      
      
function reset(event:MouseEvent):void { 
     item1_mc.x=orig1X;
     item1_mc.y=orig1Y; 
     item2_mc.x=orig2X; 
     item2_mc.y=orig2Y;
     item3_mc.x=orig3X; 
     item3_mc.y=orig3Y;
     item4_mc.x=orig4X; 
     item4_mc.y=orig4Y; 
     item5_mc.x=orig5X; 
     item5_mc.y=orig5Y;
     item6_mc.x=orig6X; 
     item6_mc.y=orig6Y;
     item7_mc.x=orig7X; 
     item7_mc.y=orig7Y;
}
            
item1_mc.buttonMode = true;
item2_mc.buttonMode = true;
item3_mc.buttonMode = true;
item4_mc.buttonMode = true;
item5_mc.buttonMode = true;
item6_mc.buttonMode = true;
item7_mc.buttonMode = true;
      

Again, if you've got only 3 draggable objects, you will need to remove EVERYTHING referencing item4_mc, item5_mc, item6_mc and item7_mc

If you've got MORE than 7 items, you will have to add those accordingly.


Last Step: Save and View your work ~

View your work by hitting the keyboard shortcut: Cmd(⌘)+Enter cmd enter

Save your work as - FIRST_NAME_LAST_NAME_PROJECT_NAME.fla]

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

 

•   ALWAYS save your projects using the following naming convention:
FIRST_NAME_LAST_NAME_PROJECT_NAME


  •   DO NOT name your project any other way - Improperly named projects will not receive credit and you will be sad.


  •   NEVER leave your work on the desktop or depend on a flash drive - instead, save your work in a folder you can find later - preferably on a virtual drive where it can be backed up.


Other Resources: http://www.danfergusdesign.com/classfiles/oldClasses/VCB324-richMedia2/exercises/matchingGame.php