flash 8 online seminar notes
Note: These are some notes i took from an online seminar by Brian Chau from Macromedia. 23/11/05
Basic Actionscript Concepts.
(Note code has not been tidied up at all.. )
Actionscript is based on javascript syntax.
This is the way we declare variables.
var product:String = “glad”;
var Number:myNum = 23;
for incrementing,
count = count + 1; is written by programmers like this..
count++;
actionscript allows us to define functions
function resetThis():Void{
counter=0;
}
Sometimes a function returns a datatype or value..
function calcsum(price):Number{
// a = b + c;
return a;
}
Conditional Logic
if (this){ do blah }
else { do other }
loops
for(var i=0;i<5;i++){
trace(i);
}
Flash object model
A button is an object. MovieClip, array, Date, Math, Key MOuse, Sound, are all objects.
objects can have properties. eg.
plane._x = 25; // horizontal position or x
Objects have methods
plane.play();
Objects have events
plane.onEnterFrame () …
We need to access those objects properties, if have a mc , we have a button inside the mc..
_root.. bottom or main timeline… dont use it..
absolute path.. _root.plane.wing
relative path.. depends where you are the time you are calling an object..
userEvents are such as..
onRelease.. e.g
button.onRelease = function(){
plane._x += 10;
}
that is event driven programming..
button.onRelease = function(){
if(plane._x <100){
plane.x +=10;}
else{ plane._x = -100;}
}
// button continuously beingt called
button.onPress = function(){
plane.onEnterFrame = function(){
this._x = (this._x <100?this._x+10:-100;
}
}
Class and Instance.. like parent and child..
// ———— //
Component - Loader.. Slide show.
var photoArray:Array = [”image.jpg”, “image2.jpg”, “image3.jpg”];
//Script assist is old normal mode.. ScriptAssist allows you to retain expert formatting..
array is full of images..
playbtn.onRelease = function(){
Filetypes of images can be .. progressive jpeg, png, gif,
eg.
array = [”pic1.gif”, pic2.gif’”];
Transition Behaviours..
fade zoom rotate. dont need a timeline or a tween..
import mx.transitions.*;
import mx.transitions.easing.*;
import mx.transitiions.blah.*;
var tType:Object = new Object();
tType = { type:Fade, direction:Transition.IN, duration:3, easing:None.easeNone);
TransitionManager.start(”change”, doChange);
Flash player 8 has great expressiveness..
you have pixel level control.. you can control pixel at runtime..
BitmapData
———–
import flash.display.BitmapData;
var bg:BitmapData = new BitmapData(550,320,true, 0);
bg_mc.attachBitmap(bg, this.getNextHighestDepth());
bg.perlinNoise(550,320,4, randomNum, false, false);
// this generates a bitmap with random colours..
BitmapData API
—————–
can capture pixel by pixel.
// capture from a webcam to a bitmap and attach bitmap to a movieclip.
startcam.onRelease
myvideo.attachVideo(Camera.get());
var source_0:BitmapData = new BitmapData(160,120,true, 0);
loader_0.attachBitmap(source_0,0);
//
capture_btn.onRelease = function(){
source_0.draw(my_video); // put video into bitmap
}
// level go from -16000 to 16000
// PIXEL LEVEL CONTROL
how to create apha channel mask..
put a picture.
over it put a mask on it..
flower_maskee.setMask(oval_mask);
// everything black becomes transparent
// you can create a gradient mask.. in flash 8..
//you can use bitmap filters such as blur. wont create a gradient mask
//use runtime bitmap caching..
flower_maskee.cacheAsBitmap = true;
oval_mask.cacheAsBitmap = true;
xpath
// Content.. External Data.. xml is difficult to write.. you have to go through all the nodes..
Xpath.. read xml document.. can read it by the name of the node..
// initialize datagrid
import mx.xpath.XPathAPI;
var myXML:XML = new XML();
XPathAPI.selectNOdeList(cuisineNOde, “cuisine/menu_itme/item/*));
// upload or download files..//
FileReference, method is download..
opens us to open a dialog box..
// flash communicate with a flash server..
flash talk to javascript.. fscommand.. in the old days..
we have a new api called external..
import flash.external.*;
ExternalInterface.call(”resetMyForm”, “call from flash”);
//can call function to javascript.
ExternalInterface.addCallback(”selectContnet”, this., selectcontent);
// ——————— //
