onMouseMove, onMouseDown, onMouseUp in ActionScript.

The following tutorial illustrates how to handle onMouseMove, onMouseDown, onMounseUp events.

NOTE: Minimum Flash Designer version 5.0.17 (verify revision number under “Help” > “About…”, download update if required)

  1. Launch Flash Designer and choose “Blank document” from the startup screen.
  2. Choose “Edit Field tool” and draw a rectangle to create edit text object. Edit field should appear as “Edit1″.
  3. Choose “Text Tool”, click on the frame, type the text “CLICK!” and click OK to create text object. Choose “Edit” > “Convert to Sprite”, the text should appear as “Sprite3″.
  4. Choose “Item” > “Placement Properties” and check “ActionScript Target” (for Sprite3 object), click OK. (This step is necessary to access Sprite3 in ActionScript code, for example Sprite3._visible = false)
  5. Choose “Frame” > “Frame Delay”, check “Stop” and click OK.
  6. Choose “Frame” > “ActionScript”, type the following code and click OK:

    onMouseMove = function()

    {

    // fill Edit1 with current x and y position

    Edit1 = “x: ” + _xmouse + ” y: ” + _ymouse;

    };

onMouseDown = function()

{

Sprite3._visible = true; // show “click!” text

};

onMouseUp = function()

{

Sprite3._visible = false; // hide “click!” text

};

Sprite3._visible= false; // init Sprite3 invisible

Press F9 to preview in Flash player.

Hit “Alt+F4″ to close preview.

To export Flash file choose “File” > “Export Flash SWF File”. Type the file name and click OK. To insert Flash in your web page choose “File” > “View HTML Code”. Select entire HTML code, right click mouse button and choose “Copy” from the popup menu. Click Close. Paste the code to your HTML page.

How to Modify shape color with ActionScript

Follow the steps below:

  1. Launch Flash Designer and create a blank document.
  2. Set the frame delay to “Stop” (“Frame” > “Frame Delay”).
  3. Size the frame at about 300×300 (“Frame” > “Frame Size”).
  4. Draw 2 circles with the “Ellipse Tool”.
  5. Select both shapes (Ctrl+A). Choose “Item” > “Line Width” > “None”.
  6. choose “Edit” > “Convert to Sprite”. The object should appear as “Sprite3″
  7. Right-click it and click “Placement Properties”.
  8. Check the “Action-Script Target” checkbox and click OK.

Next, create 2 color buttons below “Sprite3″.:

  1. Choose “Rectangle” tool and draw a small rectangle (about 18 x 18 pixels, hold CTRL to draw both edges equal)
  2. Change fill color to purple
  3. Choose “Action” > “OnClick” and enter the following ActionScript code: myColor = new Color(Sprite3); myColor.setRGB(0xff00ff);
  4. Duplicate the rectangle with “Edit” > “Duplicate”
  5. Change fill color to green
  6. Choose “Action” > “OnClick” and modify the following ActionScript code: myColor = new Color(Sprite3); myColor.setRGB(0x00ff00);
  7. Hit F9 to play the file.

Download the source here

How to Pass arguments to Flash movie from ASP or PHP

To pass parameters use query string after the name of SWF file. In the following example a query string was used:

<PARAM NAME=”MOVIE” VALUE=”t1039.swf?parameter1=123456789″>

and

<EMBED SRC=”t1039.swf?parameter1=123456789″

To use a parameter in Flash movie follow the steps below:

  1. Launch Flash Designer and create a blank document.
  2. Set the frame delay to “Stop” (“Frame” > “Frame Delay”).
  3. Draw a dynamic text box (with the edit field tool), the box should appear as “Edit1″
  4. Choose “Frame” > “ActionScript” and enter the code to initialize the box Edit1 = parameter1;
  5. Enter parameters under “Movie” > “Export Options”
  6. Export SWF file and choose “File” > “View HTML Code” to verify if the agrument is visible in the code:

Hit F9 to preview the movie.

Choose “File” > “Export Web Page” to view a sample web page with the movie.

Drive the parameter with ASP or PHP

As you have the HTML code ready you can build the query string dynamically with ASP or PHP.

ASP example:

<PARAM NAME=”MOVIE” VALUE=”t1039.swf?parameter1=<% =asp_parameter %>”>

PHP example:

<PARAM NAME=”MOVIE” VALUE=”t1039.swf?parameter1=<? print($php_parameter); ?>”>
Make the same changes to EMBED part of the Flash tag.

Of course you have to run the HTML page through your web server so it can execute ASP or PHP code.

Load variables from a text file to flash

Actionscript 3.0 Tutorial

Load parameters from a text file to Flash animation using loadVariables() function.

Text file must be in the format:

param1=value1&param2=value2

param1=value1&param2=value2 to t1012.txt

Load text file by using:

loadVariables(“t1012.txt”);

Usually in Frame’s ActionScript.

Create 2 edit fields for param1 and param2. Name fields Edit1 and Edit2. Create “Set Variables” button. Use the following ActionScript code for button’s OnUp (or OnClick) event:

Edit1 = param1;
Edit2 = param2;

To complete the tutorial:

  1. Create a folder and download t1012.txt file to the folder (right click on the link and choose Save Target As)
  2. Launch Alligator Flash Designer and choose “Blank document”.
  3. Choose “Frame” > “Frame Size” to set movie size to 300 x 200.
  4. Choose “Frame” > “ActionScript” and paste the following code:loadVariables(“t1012.txt”);
  5. Choose “Edit Field” tool and draw 2 edit fields.
  6. Choose “Select” tool. Double click each edit field and change “Variable name” to “Edit1″ and to “Edit2″ respectively.
  7. Choose “Button” tool and draw a button below edit fields.
  8. Choose “Select” tool. Select the button. Choose Action > OnUp. Select “actionscript” and enter the code:Edit1 = param1;Edit2 = param2;Click OK.
  9. Choose Frame > Frame Delay and check Stop at this frame, click OK
  10. Choose “File” > “Export SWF file” and export the file to the same folder where t1012.txt file is located.
  11. Choose “File” > “Export Web Page” and click OK for default options, a page with Flash animation should pop up in a new browser window. Click the button to load variables into edit fields.

The script will not work in preview mode unless you put txt file in the temp folder.

how to Launch email from Flash animation

Create 2 edit fields for email address and for subject. Name email field “Address” and subject field “Subject”. Create “Send” button. Use the following ActionScript code for button’s OnUp (or OnClick) event:

mailto = "mailto:" + Address + "?subject=" + Subject;
getURL(mailto,"_self");
  1. Launch Flash Designer. Choose “Frame” > “Frame Size” to set movie size (200 x 200).
  2. Choose “Edit Field” tool and draw 2 edit fields.
  3. Choose “Select” tool. Double click each edit field and change “Variable name” to “Address” and “Subject”. Make sure HTML is not checked.
  4. Choose “Button” tool and draw a button below edit fields.
  5. Choose “Select” tool. Choose “Action” > “OnClick”. Select “Action Script” and enter the code. Click OK.mailto = “mailto:” + Address + “?subject=” + Subject;getURL(mailto,”_self”);
  6. Change frame duration to “stop” (choose “Frame” > “Frame Delay” and check “Stop”, click OK)
  7. Press F9 to preview the animation.

Download Flash Designer SFD file:  download

See also:  Create and validate a form in Flash

See also:  Send a form with PHP

To set fixed email address and subject use Get URL field:

Mailto Syntax

Address message to multiple recipients ,   (comma separating e-mail addresses)
Add entry in the “Subject” field subject=Subject Text
Add entry in the “Copy To” or “CC” field cc=sales@domain.com
Add entry in the “Blind Copy To” or “BCC” field bcc=sales@domain.com
Add entry in the “Body” field body=Your message here

Separate parameters with &.

Example

mailto:support@domain.com?subject=tutorial&cc=sales@domain.com

Breaking the body into lines

Use %0A as line break, for example:

mailto:support@domain.com?subject=tutorial&body=this body has%0Atwo lines

Sending email directly from Flash

Flash Player will launch your default mail application to complete and send out the email. To send the email directly you have to execute a web based email script, usually provided by your internet provider. We can’t give any exact instructions because the script is provider specific. You have to build a query string and use getURL function to execute the script, for example:

body = “This is message body”;

email = “someone@server.com”;

querystring = “http://www.server.com/emailscript.php?” + “body=” + body + “&email=” + email;

getURL(querystring,”_self”);