Action Script 3.0

Páginas: 17 (4237 palabras) Publicado: 18 de junio de 2012
Comments
// blah blah blah or /* blahblah */
Trace Statements
trace("Hello"); = makes message appear on output window
To find out about properties = highlight property and press f7

Variables
Containers that hold or represent data. Can hold different types of data. Can hold multiple pieces of data
Ex Syntax
var name:type of data = "value";
var myName:String = "Marco";Assigning Values to Variable
var userName:String;
userName = "Marco";

Retrieving Variable Values
var userName:String;
userName = "Marco";
trace(userName);

Different Data Types
var myNum:Number = 3; supports all numbers
trace(myNum); 3
var myNum:int = -3.12; supports + and - numbers
trace(myNum); -3
var myNum:uint = 3;
trace(myNum); 3 supports + numbers

Functions
Reusableblocks of code, Perform repetitive task, Group related functionality
Flash has pre built in functions
stop(); = Stops from looping
gotoAndPlay(#); = jumps to slide# and starts playing
gotoAndStop(#); = jumps to slide# and stops playing

Understanding Syntax of Function
function getGroceries() {
trace("milk");
trace("flour");
trace("sugar");
trace("squash");
}
getGroceries();BrowsOutput = milk flour sugar squash

Understanding Parameters
Parameters are values that are past to the inside of the function
function getGroceries(item4:String) {
trace("milk");
trace("flour");
trace("sugar");
trace(item4);
}
getGroceries("chiles");
BrowsOutput = milk flour sugar chiles
Ex 2
function getGroceries(item1:String, item2:String, item3:String, item4:String) {trace(item1);
trace(item2);
trace(item3);
trace(item4);
}
getGroceries("sugar", "ham", "apples", "chiles");
BrowsOutput = sugar ham apples chiles

Returning Values
function getTotal():Number{
var hamPrice:Number = 4.99;
var chiliPrice:Number = 1.99;
return hamPrice + chiliPrice;
}
trace(getTotal());
BrowsOutput = 6.98

Using Local Variables
There called local because there inside thefunction
function getGroceries() {
var steakPrice:Number = 4.99;
var chiliPrice:Number = 1.99;
trace(steakPrice);
}
getGroceries();
BrowsOutput = 4.99

Using Global Variables
There called local because there outside the function
var steakPrice:Number = 4.99;
function getGroceries() {
var chiliPrice:Number = 1.99;
}
trace(steakPrice);
BrowsOutput = 4.99

Understanding dotSyntax
tv_mc.alpha = .5;
tv_mc.x = 0;

Controlling Display Properties
Putting object inside the other
container_mc.addChild(tv_mc);
To take out and put back
addChild(tv_mc);

Creating Objects Dynamically
Click on library >choose object >right Click >properties>check Export for ActionScript>name class>click Ok
Open Actions and type
var tv_mc:XX = new XX();
addChild(tv_mc);
createvariable tv_mc with data type XX due to class = create a instills with new
of the XX class

Controlling Nested Movie Clips
Click actions layer on the first keyframe
Open actions
container_mc.alpha = .2; Targets both parent and child objects
container_mc.tv_mc.alpha = .2; Targets child objects only
or
container_mc.getChildByName("tv_mc").alpha = .2;

Events and Event ListenersOccur all the time Mouse click Key press File loaded
Listeners connect events to functions
Handlers respond to events

Connect button with a mouse click
on_btn.addEventListener(MouseEvent.CLICK, turnOnTV);
function turnOnTV(xxx:MouseEvent):void
{
trace("clicked!");
}

Ex 2
on_btn.addEventListener(MouseEvent.CLICK, turnOnTV);
function turnOnTV(xxx:MouseEvent):void
{animation_mc.play();
}

name of button in the instance name field
method to use
look for any mouse action
property meaning listening for a mouse click
name of function going to be used on
next create function to handle the event
function name (name:datatype):void
{
name of animation.what to do;
}

Handling Other Mouse Events
on_btn.addEventListener(MouseEvent.MOUSE_DOWN, turnOnTV);...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Action script
  • Action script
  • ¿ Que Es Action Script?
  • Action script
  • Curso De Action Script
  • Practica de action script
  • Action Script
  • Action Script

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS