Monday, November 29, 2010

ActionScript 3 Objects, Properties and Methods

Actionscript 3

Objects

ActionScript objects provide a means of moving graphic elements dynamically, building applications, organizing data, and more. You accomplish these tasks by using or setting object property values and invoking object methods.

Global objects

In your Flash application there are some objects that are classified asglobal, or unique to the movie as a whole. The mouse, for example, is defined as a global object, like a Mouse object. The mouse is global because you can only have one mouse in your application and can not create an instance of it. Objects like movie clips, text fields, and sounds must be created with components and instances to be used.

Flash Global Objects:

  • Math
  • Accessibility
  • Key
  • Mouse
  • Selection
  • Stage
  • System

Object classes

A class of objects represents a group of object instances within your project that share the same basic structure and functionality. For example, all movie clip instances belong to the MovieClip class of objects

import flash.display.MovieClip;
var myMovie:MovieClip = new MovieClip();

Properties

Certain objects, such as MovieClips for example, have properties and attributes which can be configured via ActionScript. Properties are simple attributes of the object, such as its width, its height, its horizontal position and its vertical position. In order for a property to be configured you need to use the dot (.) operator to access the property and the assignment (=) operator to set a new value for it.

var myMovie:MovieClip = new MovieClip();
myMovie.x = 300;
myMovie.y = 100;

myMovie is the object, x is the property, 300 is the value

Methods

Objects also have methods, or functionality actions that the object can perform. If your object is a video object, you can tell this object to play the video. Any action that the object can perform is called a method.

import flash.media.Video;

var myVideo:Video = new Video();
myVideo.play();

Some methods require additional information to execute the action. The Loader Class is responsible for loading external graphical elements into your movie, in order for it to perform the .load() method you must specify the URL of the file to be loaded:

import flash.display.Loader;

var myLoader:Loader = new Loader();
myLoader.load(new URLRequest("MyPic.png"));

Saturday, November 20, 2010

Create A Basic Contact Form With PHP and ActionScript

Creating the Form

  1. A TextInput Component for the email address of the sender named email_txt.
  2. A TextInput Component for the email address of the sender named name_txt.
  3. A TextField Component for the email address of the sender named message_txt.
  4. A Button Component named submit_btn, and Labeled Submit Message.

 

flash email form

The PHP Code (mail.php)

<?php
$to = "myAddress@mySite.com";
$subject = ($_POST['senderName']);
$message = ($_POST['senderMsg']);
$message .= "\n\n---------------------------\n";
$message .= "E-mail Sent From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">\n";
$headers = "From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">\n";
if(@mail($to, $subject, $message, $headers))
{
echo "answer=ok";
}
else
{
echo "answer=error";
}
?>

 

The Button Event Handler

import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.net.URLVariables;

submit_btn.addEventListener(MouseEvent.CLICK, sendMessage);
function sendMessage(e:MouseEvent):void
{
var my_vars:URLVariables = new URLVariables();
my_vars.senderName = name_txt.text;
my_vars.senderEmail = email_txt.text;
my_vars.senderMsg = message_txt.text;

var my_url:URLRequest = new URLRequest("mail.php");
my_url.method = URLRequestMethod.POST;
my_url.data = my_vars;

var my_loader:URLLoader = new URLLoader();
my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
my_loader.load(my_url);

name_txt.text = "";
email_txt.text = "";
message_txt.text = "You have created a contact form with ActionScript 3.0 & PHP";

}

 

Adding Form Validation

Hide the submit button until the user types the word validate

var valid:String = "validate";
submit_btn.visible = false;
validate_txt.addEventListener(TextEvent.TEXT_INPUT, textInputHandler);

function textInputHandler(event:TextEvent):void
{
if (validate_txt.text = valid)
{
submit_btn.visible = true;
}
}

The contact tab has better form controls, this just shows the basics.

Wednesday, November 17, 2010

Loading An External Video With The ComboBox Component

Flex Builder 4 Flash Video Actionscript 3

import flash.events.Event;

vidPicker.addEventListener(Event.CHANGE, nextVid);
function nextVid(event:Event):void
{
myVideo.source = vidPicker.selectedItem.data;
vidTxt.text = vidPicker.selectedItem.label;
var vidSmooth:Video = event.target.content;
vidSmooth.smoothing = true;
}

Saturday, November 13, 2010

Bezier Tween in ActionScript 3

Flex Builder 4 Flash Video Flash Video

TweenMax also introduces an innovative feature called "bezierThrough" that allows you to define points through which you want the bezier curve to travel. Use the code below and alter the bezierThrough values, adding more or less values.

import gs.TweenMax;
import fl.motion.easing.*
TweenMax.to(mc, 3, {x:344, y:351, bezierThrough:[{x:78.2, y:198.15}, {x:260.05, y:93.75}, {x:348.8, y:123.3}], ease:Bounce.easeOut});

Click on the ball to start the tween


  • x:344, y:351 (The tween x & y values)
  • x:78.2, y:198.15 (1st Bezier point)
  • x:260.05, y:93.75 (2nd Bezier point)
  • x:348.8, y:123.3 (3rd Bezier point)

Wednesday, November 10, 2010

Get Adobe Flash Media Development Server For Free

Flex Builder 4 Flash Video

Flash Media Server 4Adobe Flash Media Server is software that focuses on being a streaming server and data to the Flash Platform helps by providing a better and richer experience for the user. Adobe today announced a new family Flash Media Server 4, with innovations such as Dynamic IP multicast, HTTP Streaming and of course, RTMFP(Real Time Media Flow Protocol)


Adobe Flash Media Server 4 Family

Adobe Flash Media Server 4 Family

The family Flash Media Server 4 now includes the following members:

Adobe Flash Media Development Server software contains all the features in Adobe Flash Media Enterprise Server 4 software, but with a limit of 10 simultaneous RTMP connections and 50 simultaneous RTMFP connections, and time limits for IP multicast and live HTTP Dynamic Streaming.

Flash Media Server Developer Center

http://www.adobe.com/products/flashmediaserver/
http://blogs.adobe.com/ktowes/2010/09/announcing-flash-media-server-4.html
http://blogs.adobe.com/conversations/2010/09/adobe-debuts-new-technologies-and-improved-video-workflows-at-ibc-flash-media-server-4-announced.html

Wednesday, November 3, 2010

Timing Animation With ActionScript 3

Flex Builder 4 Flash Video Flash Video

Tween 2 Movie Clips without using the Timeline

Start a tween, and while it is playing start another one using the Timer Class and TimerEvent. First you have to import the classes, then create the timer. the Timer() constructor takes two parameters. The first parameter controls how frequently the TimerEvent.TIMER event gets dispatched (in milliseconds). The second parameter is the number of times that the TimerEvent.TIMER event will be dispatched before stopping.

import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.utils.Timer;
import flash.events.TimerEvent;
var timer:Timer = new Timer(1500, 1);//Creating the timer
timer.addEventListener(TimerEvent.TIMER, nextTween);
timer.start();

var myTweenX:Tween = new Tween(movieClip, "alpha", None.easeOut, 0, 1, 3, true);

function nextTween(e:TimerEvent):void{
var myTweenAlpha:Tween = new Tween(movieClip, "x", Strong.easeOut, 0, 300, 3, true);
timer.removeEventListener(TimerEvent.TIMER, nextTween);
}

ActionScript 3.0 Language Reference

Tuesday, November 2, 2010

Customizing The Right Click Context Menu With ActionScript 3

Flex Builder 4 Actionscript Tutorials

Right Click The SWF

Context Menu With Hyperlink

The code will make a context menu when users right click on the SWF. Clicking on the site link will open the web page of whatever link you use in the mySiteLink. This is good for blog posts and allows users to see the author of the content.

import flash.net.URLRequest;
import flash.ui.ContextMenu;
var myMenu:ContextMenu = new ContextMenu();
var copyright:ContextMenuItem = new ContextMenuItem( "Copyright© yoursite.com" );
var credit:ContextMenuItem = new ContextMenuItem( "Your Name Here" );
copyright.addEventListener( ContextMenuEvent.MENU_ITEM_SELECT, visitMySite );
credit.addEventListener( ContextMenuEvent.MENU_ITEM_SELECT, visitMySite );
credit.separatorBefore = false;
myMenu.hideBuiltInItems();
myMenu.customItems.push(copyright, credit);
this.contextMenu = myMenu;
function visitMySite(e:Event)
{
var mySiteLink:URLRequest = new URLRequest( "http://www.yoursite.com" );
navigateToURL( mySiteLink, "_parent" );
}

 

Removing Specific Menu Items

var my_menu:ContextMenu = new ContextMenu();
my_menu.builtInItems.forwardAndBack = false;
my_menu.builtInItems.loop = false;
my_menu.builtInItems.play = false;
my_menu.builtInItems.print = false;
my_menu.builtInItems.quality = false;
my_menu.builtInItems.rewind = false;
my_menu.builtInItems.save = false;
my_menu.builtInItems.zoom = false;
contextMenu = my_menu;

Monday, November 1, 2010

Free Flash Extension: MotionSketch

Flex Builder 4 Flash Video Flex Builder 4

MotionBrush: Free Actionscript Class

motion sketch

Here's a comprehensive, sortable list of more Flash Extensions from ajarproductions

Merapi Bridges AIR with and Java

AIR Flash Builder Flash Video
The Merapi Project

Merapi is a framework that bridges an AIR application with a Java application, both running on the desktop. This communication is accomplished through a class that exists in Java and ActionScript called merapi.Bridge. The simplest way to interact from AIR to Java is by sending and receiving messages though the bridge.

Get Merapi from Google Code

Related Posts Plugin for WordPress, Blogger...