Best Practices:
HTML
- Multipage applications
- User sessions expire
Stress between pages when screen whites out
Flash
- Single screen applications
- Retain state offline (wi-fi drops)
- Maintains context
Best Practice Resource Links:
Robert Hoekman, Jr.
http://www.oreillynet.com/pub/au/1829
https://admin.adobe.acrobat.com/_a200985228/p10297044/
http://www.boxesandarrows.com/person/1003-rhoekmanjr <-- nothing there but interesting you can comment on authors?
User based actions / time based actions.
Normal mode: has been added back in somewhat, in Script Assist.
Loading SWFs:
Create a movieclip to hold / frame what you're loading in.
Loading a swf into a project:
var myMCL:MovieClipLoader = new MovieClipLoader ();
myMCL.loadClip("slideshow_starter.swf","container");
MovieClipLoader "class" - a class is a grouping of objects
Button = class
when you code things you are creating an instance of the class, just as you would if you were dragging an object from the library on to the stage.
Components:
Data, movie playback, user interface devices - to access to go "Window > Components" -
FS Commands
Control how your movie publishes, fills screen, scales, etc. or create a "quit" button.
Bandwidth Profiler:
Can be used to see how big files are (?) in your movie. Useful to see how your movie would stream over various internet connections.
AS2.0 -
who.what
object - event
property
Datatypes
- Primitive Data Types
- String - always in "quotes" (other primitives types are not)
- Number - 5
- Boolean - true / false
- Reference Data Types ?
Variables
- variable declaration = keyword "var" - var nQuantity, sQuantity, bQuantity
- variables cannot be reserved words in ActionScript - you can tell as you type in a word if it turns blue don't use it.
- Name of variable has to start with either a letter, _, or $ - typically it's a letter.
- Name can only have letters, numbers, underscores or dollarsigns, no special characters, spaces, etc.
Datatypes are stored in variables.
var nQuantity:Number;
Assignment statement:
nQuantity = 5;
trace(nQuantity); <-- will display 5 in output panel, good for debugging...
You can declare multiple values to a variable (why would you want to do that???)
You can combine declaration and assignment statements:
var nQuantity:Number = 5;
You have to be consistent in assigning datatypes.
Expressions & Operators
An Expression is anything that can be resolved to a single value...
var nQuantity:Number = 5;
trace(nQuantity);
Expressions become more complex when you combine an operator
Arithmatic, Assignment, Comparison, Logical, Miscellaneous...
nQuantity: Number = 5;
nQuantity = nQuantity + 1;
or
nQuantity += 1
or
nQuantity++;
IF statement
Some lines of code will execute only if a certain condition is met.
var nQuantity:Number = 5;
if (nQuantity == 5) {
trace ("Yes the condition was met.");
}
else {
trace("No the condition was not met");
}
Switch statement
A shorter way to code if / else statements....
For statement
"For statements are fun" - what's more fun, writing 209850298475 statements or 1? It's a TIMESAVER. Y ou can reduce code from 1000s of lines to 30 or so lines.
Long and cumbersome way:
trace("Using for statements is a lot of fun.");
trace("Using for statements is a lot of fun.");
trace("Using for statements is a lot of fun.");
trace("Using for statements is a lot of fun.");
trace("Using for statements is a lot of fun.");
trace("Using for statements is a lot of fun.");
trace("Using for statements is a lot of fun.");
trace("Using for statements is a lot of fun.");
trace("Using for statements is a lot of fun.");
trace("Using for statements is a lot of fun.");
For Statement way:
for(var i:Number = 0; i < 10; i++) {
trace("Using for statements is a lot of fun.");
}
syntax:
checks var once
checks condition
goes to body
reaches end
returns, runs updater - adds 1 to i
checks conditional
goes to body, runs
runs updater,
checks condition
Repeats this process until condition is no longer met.
Example:
var nPieces:Number = 50;
var nRowsColumns = Math.floor(Math.sqrt(nPieces));
nPieces = nRowsColumns * nRowsColumns;
var nX:Number = 0;
var nY:Number = 0;
var mcPiece:MovieClip;
this.createEmptyMovieClip("mcMask", this.getNextHighestDepth());
for(var i:Number = 0; i < nPieces; i++) {
mcPiece = mcMask.attachMovie("MaskPiece", "mcPiece" + i, mcMask.getNextHighestDepth(), {_x: nX, _y: nY});
mcPiece._width = (mcImage._width + mcPiece._width)/nRowsColumns;
mcPiece._height = mcPiece._width;
nX += mcPiece._width;
if((i + 1) % nRowsColumns == 0) {
nX = 0;
nY += mcPiece._height;
}
}
mcMask._x = mcImage._x - mcPiece._width/2;
mcMask._y = mcImage._y;
mcImage.setMask(mcMask);
Functions
Make code more readable - can help you to organize your code. Example:
// Syntax
// keyword - function
// name the function, similar to variable (no spaces, etc.)
// part after colon describes what datatype is returned as a value
// now that function is defined - you call it
function displayMessage ():Void {
trace("Whoa, Functions Rule!");
}
displayMessage();
Parameter / Argument = tomato / tomato = they are the same thing.
A Parameter is a way to pass information to the function.
// Parameter added to this can add variation to a function
// Parameters don't use var
// is a parameter a datatype?
function displayMessage (sAdjective:String, sPunct:String):Void {
trace("Whoa, Functions " + sAdjective + " Rule!" + sPunct);
}
displayMessage("totally" , "!");
displayMessage("really" , "!!!");
// what happens when you pass the wrong type of data - it won't let you.
Another function Example:
function multiply(nA:Number, nB:Number):Number {
var nProduct:Number = nA * nB;
return nProduct;
}
trace(multiply(5,6));
Functions like to take but don't like to give - variable scope?....certain variables that you declare in your code are only available in certain portions:
function displayValue():Void {
trace(sValue);
}
var sValue:String = "Outside Variable";
displayValue();
The function has access to the variable outside
function displayValue():Void {
var sValue:String = "Inside Variable";
trace(sValue);
}
var sValue:String = "Outside Variable";
displayValue();
would display "Inside Variable" ---- inside of the function preference is given to local variable. This means, variable scope enables you to declare variables with the same names inside different functions... keep your code in the correct scopes.
This function is similar to the for statement example, but it adds a mask piece one by one...
function addToMask():Void {
var nDepth:Number = mcMask.getNextHighestDepth();
mcPiece = mcMask.attachMovie("maskPiece", "mcPiece" + nDepth, nDepth);
mcPiece._x = nX;
mcPiece._y = nY;
nX += mcPiece._width;
if(nX >= mcImage._width + mcPiece._width) {
nX = 0;
nY += mcPiece._height;
}
}
var nX:Number = 0;
var nY:Number = 0;
var mcPiece:MovieClip;
mcImage._width = 400;
this.createEmptyMovieClip("mcMask", this.getNextHighestDepth());
mcImage.setMask(mcMask);
mcMask._x = mcImage._x - 25;
mcMask._y = mcImage._y;
var nStageWidth:Number = Stage.width;
mcAdd.onRelease = function():Void {
addToMask();
};
Set Interval
"Best Kept Secret" - interval notifications to user (want to tell them something every 5 minutes) also to create really powerful animation... better than onEnterFrame...using set interval you can tell Flash how frequently you want to do something.
You are always going to be using Set Interval with a function.
function displayMessage():Void {
trace("We like setInterval");
}
// set interval used to call display message once per second.
// interval is default to milliseconds so you have to calculate, one second is one thousand milliseconds...
var nInterval:Number = setInterval(displayMessage, 1000);
when I tested this movie I couldn't make it stop :P
function displayMessage():Void {
trace("We like setInterval");
nTimes++;
if (nTimes >= 10) { <-- this is where you tell it how many times to do something
clearInterval(nInterval);
}
}
// set interval used to call display message once per second.
// interval is default to milliseconds so you have to calculate, one second is one thousand milliseconds...
var nTimes:Number = 0;
var nInterval:Number = setInterval(displayMessage, 1000);
// how do you make it stop...use clear interval function
// if you called clear interval immediately....
Example - this code adds piece to a mask once per second:
function addToMask():Void {
var nDepth:Number = mcMask.getNextHighestDepth();
mcPiece = mcMask.attachMovie("maskPiece", "mcPiece" + nDepth, nDepth);
mcPiece._x = nX;
mcPiece._y = nY;
nX += mcPiece._width;
if(nX >= mcImage._width + mcPiece._width) {
nX = 0;
nY += mcPiece._height;
}
}
var nX:Number = 0;
var nY:Number = 0;
var mcPiece:MovieClip;
mcImage._width = 400;
this.createEmptyMovieClip("mcMask", this.getNextHighestDepth());
mcImage.setMask(mcMask);
mcMask._x = mcImage._x - 25;
mcMask._y = mcImage._y;
var nStageWidth:Number = Stage.width;
var nAddMaskInterval:Number = setInterval(addToMask, 1000);
To make animation faster, change the number in setInterval - remember default interval is in milliseconds.
Objects & Arrays
Objects
Two different concepts that are related:
Class - blueprint
Object - created from the blueprint.
In Flash 8, see "ActionScript 2.0 classes" - "Core" - "Array"
Methods - functions that are associated with an object
Properties - variables that are associated with an object
Constants
Classes generate objects
When you want flash to generate an object, you create a "constructor"
var oInfo:Object = new Object(); <-- called the constructor, assigned to a variable called oInfo. This is also called "instantiation".
Arrays (Array class... very important!)
An array is a way that you can organize your data. I.e. if you have 30 variables that contain related information... you can use an array to organize all that information into one object and all of those variables or vaules that were previously stored there can by organized by index. An array could contain 30 pieces of information that is assigned an index...
Slide example - say you have a lot of country names... you could assign them all variables, sCountry name 1, 2, etc.
An array is like a table with slots, numbers on the left are the index then next column are the names. You can loop, sort, etc.
How are they used in ActionScript?
Constructor technique:
//var aValues:Array = new Array("John","Sarah","Paul");
//trace(aValues);
// created array
// add information
// array access notation
var aValues:Array = new Array();
aValues[0] = "John";
aValues[1] = "Sarah";
aValues[2] = "Paul";
trace(aValues);
// Push method - method a function that is associated with an object
var aValues:Array = new Array();
aValues.push("John");
aValues.push("Sarah");
aValues.push("Paul");
trace(aValues);
Why so many ways? Constructor technique, Array access technique, Push technique - it all depends on what you are trying to do. Appending a new value might use push, if you want to assign value to a particular index, array access might be better...etc.
array class has sort method -
aValues.sort(); <-- you can pass a parameter to the sort method
var aValues:Array = new Array();
aValues.push("John");
aValues.push("Sarah");
aValues.push("Paul");
aValues.sort(Array.DESCENDING);
trace(aValues);
This is case sensitive, you can turn that off....
var aValues:Array = new Array();
aValues.push("John");
aValues.push("Sarah");
aValues.push("Paul");
aValues.sort(Array.DESCENDING);
for(var i:Number = 0; i < 3; i++){
trace(aValues[i]);
}
diplays array in order... if you want to add....you can use length as a variable
var aValues:Array = new Array();
aValues.push("John");
aValues.push("Sarah");
aValues.push("Paul");
aValues.push("Arun");
aValues.sort(Array.DESCENDING);
for(var i:Number = 0; i < aValues.length; i++){
trace(aValues[i]);
}
(took out the 3 and added .length)
Associative Arrays
An array object uses the Array class - lets you order data by integer index (1,2,3,4,5 etc.) Associative arrays use the Object class. (object / Object - Object is a class name, object with a lower case "o" means instances of classes, i.e. Array class, Movie Clip class, etc.)
Associative arrays help you organize your data by string rather than integer.
For example, you might have a company with people, titles, etc. They don't have a particular order but they do have particular significance and they are all related. You'd need to give each piece of data a key in order to reference it.
Instantiate an associative array:
Movie Clips and Buttons
Flash 8 - inside Action Script 2.0 - Classes folder - Movie - you'll see "Buttons" and "Movie Clips." Movie Clips and Buttons are actually objects.
Button class
- Methods
- Properties - main properties _alpha, _x and _y - also _width & _height
- Event Handlers (formerly Events in Flash MX)
Movie Clip class
- Methods
- Properties - very similar to button properties
- Drawing Methods
- Event Handlers
Movie Clip Addressing
Use movie clips mostly - for addressing / targeting. "Addressing" is for nested movie clips - targeting is same term.
Real world things that have nested relationships - World, US, New York, Manhattan. Use dot syntax to tell flash where things are in the hierarchy.
world.unitedstates.newyork.manhattan
Addressing.
mcThreeInOne.mcRaindrop._visible = false <-- last item is a built in property that is true or false.
Event Handler Methods
Flash event model: flash is going to only be able to run action script coe when a certain thing occurs, the thing is called an "event". i.e. someone throws a ball, you can only catch the ball once it has been thrown.
Key frames are implicit event handlers.
When ever the play head enters a frame, this is an event - (code is executed), the event handler is the keyframe itself.
Button events - handled both by buttons and movie clips.
Old school way - on and onClip event handlers --- these do not allow you as much programmatic control
Event handler method <-- new school? :P
Associate a function with an instance... when a certain even occurs, run that function.
onPress and onRelease
mcThreeInOne.mcRaindrop._visible = false;
mcThreeInOne.onPress = function():Void {
mcThreeInOne.mcRaindrop._visible = !mcThreeInOne.mcRaindrop._visible;
trace("onPress has been called.");
};
here we have declared anonymous / inline function, note syntax.
=! means not equal... this would make the visibility toggle on and off.
If we were to declare this method in a more complex scenario it's possible that it might not work. but, you can also use a relative address that tells flash to target something inside of mcThreeInOne
This, whenever it is used in an event handler method, refers to the object itself.
mcThreeInOne.mcRaindrop._visible = false;
mcThreeInOne.onPress = function():Void {
this.mcRaindrop._visible = false;
trace("onPress has been called.");
};
mcThreeInOne.onRelease = function():Void {
this.mcRaindrop._visible = true;
};
This makes the object visible on release. You can also use onRollOver, onRollOut - 4 most common are onPress, onRelease, onRollOut, onRollOver.
Basic Animation Effects
mcThreeInOne._x = 0;
mcThreeInOne._y = 0;
Shifts mc to upper left hand corner of stage.
Set transparency
mcThreeInOne._x = 0;
mcThreeInOne._y = 0;
mcThreeInOne._alpha = 30;
// use actionscript to animate these properties over time
// delcare a function
// use setInterval to call animate function
function animate():Void {
mcThreeInOne._x++:
mcThreeInOne._y++;
mcThreeInOne._alpha++;
}
mcThreeInOne._x = 0;
mcThreeInOne._y = 0;
mcThreeInOne._alpha = 0;
var nInterval:Number = setInterval(animate, 100);
To make more smooth:
function animate():Void {
mcThreeInOne._x++:
mcThreeInOne._y++;
mcThreeInOne._alpha++;
updateAfterEvent();
}
mcThreeInOne._x = 0;
mcThreeInOne._y = 0;
mcThreeInOne._alpha = 0;
var nInterval:Number = setInterval(animate, 10);
This code takes a series of 7 images and reveals them in a slide show. Once the user has viewed all images they can reset.
var aImages:Array = new Array(mcOne, mcTwo, mcThree, mcFour, mcFive, mcSix, mcSeven);
var nCurrentIndex:Number = 0;
mcNextButton.onRelease = function():Void{
aImages[nCurrentIndex]._alpha = 0;
nCurrentIndex++;
};
/* to create the code to give functionality to the next button - create a new array that will store references to each movie clip.
Declare a new array (new statement) pass the constructor parameter values (mcOne - Seven).
Create another variable called nCurrentIndex - keeps track of which image is currently being displayed, 0 corresponds to first element of index.
Create an instance of mcNext button - create on release event handler that sets alpha to zero so that it will display the images that are underneath it.
Then increment value of nCurrent index so that the next image that will be hidden is the next image in the array.
So this code is revealing each image by hiding the previous one.
*/
// Define functionality of reset button - event handler
// tell flash to loop through again and use for to make alpha 100
// make sure you reset nCurrentIndex to 0 so that flash will know to start with the first element of the array..."reset" goes to beginning of movie.
mcResetButton.onRelease = function():Void {
for(var i:Number = 0; i < aImages.length; i++){
aImages[i]._alpha = 100;
}
nCurrentIndex = 0;
};
This makes slides fade rather than simple cuts:
var aImages:Array = new Array(mcOne, mcTwo, mcThree, mcFour, mcFive, mcSix, mcSeven);
var nCurrentIndex:Number = 0;
var nInterval:Number;
mcNextButton.onRelease = function():Void {
clearInterval(nInterval);
nInterval = setInterval(fadeImage, 50, aImages[nCurrentIndex]);
};
mcResetButton.onRelease = function():Void {
for (var i:Number = 0; i<aImages.length; i++) {
aImages[i]._alpha = 100;
}
nCurrentIndex = 0;
};
function fadeImage(mcImage:MovieClip):Void {
mcImage._alpha -= 10;
if (mcImage._alpha<=0) {
clearInterval(nInterval);
nCurrentIndex++;
}
updateAfterEvent();
}
Best Practices: Highlighted areas make the slide show run more smoothly, if the clearInterval weren't there, show might get stuck if user hits rapidly, and updateAfterEvent makes it more smooth as well.
Draggable Movie Clips
You can make a movie clip draggable with a single method call.
mcRaindrop.onPress = function():Void{
this.startDrag();
};
Make it stop dragging:
mcRaindrop.onPress = function():Void{
this.startDrag();
};
mcRaindrop.onRelease = function():Void{
this.stopDrag();
};
Parameters that could go inside are (lockcenter, top, right, left, bottom) so entries would be (true/false,
mcRaindrop.onPress = function():Void{
this.startDrag(true);
};
mcRaindrop.onRelease = function():Void{
this.stopDrag();
};
mcRaindrop.onReleaseOutside = mcRaindrop.onRelease;
To constrain area on the stage:
mcRaindrop.onPress = function():Void{
this.startDrag(true, 0, 0, 300, 300);
};
mcRaindrop.onRelease = function():Void{
this.stopDrag();
};
mcRaindrop.onReleaseOutside = mcRaindrop.onRelease;
Hit Test
To check if two (or more) movie clips are overlapping.
mcRaindrop.onPress = function():Void {
this.startDrag();
};
mcRaindrop.onRelease = function():Void {
this,stopDrag();
var bIsOverlapping:Boolean = this.hitTest(mcSunshine);
if (bIsOverlapping){
this._visible = false;
}
};
mcRaindrop.onReleaseOutside = mcRaindrop.onRelease;
// want to make mcRaindrop disappear when it is dropped on mcSunshine.
// create local variable, boolean value is true or false
// use value in if statement - use variable as expression inside if statement - used it as conditional expression in the if statement
Attach Movie
Adding the movie clip content to stage entirely with actionscript affords a LOT of programmatic control over what goes on in the movie. There are things you can't do if you're just placing it on the stage at "authoring time".
Use the method called "Attach Movie" - attachMovie
The way it works is, it tells flash that we want to add an instance of a symbol from the library nested within the movie clip from which the method is called. In order to accomplish that we need to tell flash to export the symbols from the library when it exports the swf, the reason for that is if we don't and we haven't created an instance on the stage during authoring time then flash is going to automatically leave those symbols out of the SWF - the reason is simple, it's to conserve file space. We need to tell flash we DO want it to export the files... we do this through linkage....
hmmm... I've seen that :P
OOOHHH you do "export for actionscript" when you have a clip that isn't actually ON the stage. Do this on all mcs you're going to use.
Timeline itself is an object....use relative references...
this.attachMovie("idName", newName, depth [, initObject])
this.attachMovie("ImageOne","mcOne", 1);
//depth is stacking order, you can only attach one instance per depth.
Attaching multiple movie clips:
New method of movie clip class called "get next highest depth" will always return next available depth
this.attachMovie("ImageOne","mcOne", this.getNextHighestDepth());
Note:
identifier (named in linkage)
instance name
level
this.attachMovie("ImageOne","mcOne", this.getNextHighestDepth());
this.attachMovie("ImageTwo","mcTwo", this.getNextHighestDepth());
this.attachMovie("SubmitButton","mcSubmit", this.getNextHighestDepth());
mcSubmit._y = mcTwo._height;
This code makes the button appear just beneath the image.
this.attachMovie("ImageOne","mcOne", this.getNextHighestDepth());
this.attachMovie("ImageTwo","mcTwo", this.getNextHighestDepth());
this.attachMovie("SubmitButton","mcSubmit", this.getNextHighestDepth());
mcSubmit._y = mcTwo._height;
//this code makes the button appear just beneath the image.
mcSubmit.onRelease = function():Void{
mcTwo._visible = !mcTwo._visible;
};
// this tells flash to toggle visibility
// here is another method , swap depth... changes the order rather than toggling visibility
this.attachMovie("ImageOne","mcOne", this.getNextHighestDepth());
this.attachMovie("ImageTwo","mcTwo", this.getNextHighestDepth());
this.attachMovie("SubmitButton","mcSubmit", this.getNextHighestDepth());
mcSubmit._y = mcTwo._height;
//this code makes the button appear just beneath the image.
mcSubmit.onRelease = function():Void{
mcTwo.swapDepths(mcOne);
};
Practice:
// define a custom function
// within the function define a parameter
// assign local variable nIndex
// assign local variable mcWindow so you can reference without having to use array //access notation...instead use attachMovie, will ask for idName, newName, depth - attach the instance that the linkage identifier that corresponds to the value of the sLinkage parameter , the new name will be called mcWindow and concatenate with sIndex to make sure there are unique names....huh???
function addWindow(sLinkage:String):Void{
var nIndex:Number = this.getNextHighestDepth();
var mcWindow:MovieClip = this.attachMovie(sLinkage, "mcWindow" +nIndex, nIndex);
mcWindow._x = 100
mcWindow._y = 100
};
THEN: now you have to call the function, we'll use onRelease, type it above:
mcButtonOne.onRelease = function();Void{
addWindow("WindowOne");
};
mcButtonTwo.onRelease = function();Void{
addWindow("WindowTwo");
};
function addWindow(sLinkage:String):Void{
var nIndex:Number = this.getNextHighestDepth();
var mcWindow:MovieClip = this.attachMovie(sLinkage, "mcWindow" +nIndex, nIndex);
mcWindow._x = 100
mcWindow._y = 100
};
THEN: adding draggable functionality and closing functionality (removeMovieClip):
mcButtonOne.onRelease = function():Void {
addWindow("WindowOne");
};
mcButtonTwo.onRelease = function():Void {
addWindow("WindowTwo");
};
function addWindow(sLinkage:String):Void {
var nIndex:Number = this.getNextHighestDepth();
var mcWindow:MovieClip = this.attachMovie(sLinkage, "mcWindow" +nIndex, nIndex);
mcWindow._x = 100;
mcWindow._y = 100;
mcWindow.mcWindowBackground.onPress = function():Void{
this._parent.startDrag();
};
mcWindow.mcWindowBackground.onRelease = function():Void{
this._parent.stopDrag();
};
mcWindow.mcCloseSquare.onRelease = function():Void{
this._parent.removeMovieClip();
};
}
// this._parent property refers to the mcWindow within nested mc.
Add code that enables depth:
// add depth toggling - tell flash to swap depths... what are you doing this with?
// delcare a variable nTopDepth
var nTopDepth:Number;
mcButtonOne.onRelease = function():Void {
addWindow("WindowOne");
};
mcButtonTwo.onRelease = function():Void {
addWindow("WindowTwo");
};
function addWindow(sLinkage:String):Void {
var nIndex:Number = this.getNextHighestDepth();
var mcWindow:MovieClip = this.attachMovie(sLinkage, "mcWindow" +nIndex, nIndex);
mcWindow._x = 100;
mcWindow._y = 100;
nTopDepth = nIndex;
mcWindow.mcWindowBackground.onPress = function():Void{
this._parent.swapDepths(nTopDepth);
this._parent.startDrag();
};
mcWindow.mcWindowBackground.onRelease = function():Void{
this._parent.stopDrag();
};
mcWindow.mcCloseSquare.onRelease = function():Void{
this._parent.removeMovieClip();
};
}
Final touches...make sure user can only open ONE instance at a time...the code above allows you to open multiple instances of each movie clip.
want to tell flash that if an instance is already open we don't want to open another instnace. We want to declare an associate array that contains information about which of the instances is currently open.
var nTopDepth:Number;
var oOpenedWindows:Object = new Object ();
// use names of linkage identifiers as KEYS for our opened windows associative array then assign to the KEYS the value that are references to the movie clip instances that are currently open....in order to do that we are going to add another line of code into the addWindow function... see highlighted...
mcButtonOne.onRelease = function():Void {
addWindow("WindowOne");
};
mcButtonTwo.onRelease = function():Void {
addWindow("WindowTwo");
};
function addWindow(sLinkage:String):Void {
if(oOpenedWindows[sLinkage] != undefined) {
return;
}
var nIndex:Number = this.getNextHighestDepth();
var mcWindow:MovieClip = this.attachMovie(sLinkage, "mcWindow" +nIndex, nIndex);
mcWindow._x = 100;
mcWindow._y = 100;
nTopDepth = nIndex;
oOpenedWindows[sLinkage] = mcWindow;
mcWindow.mcWindowBackground.onPress = function():Void{
this._parent.swapDepths(nTopDepth);
this._parent.startDrag();
};
mcWindow.mcWindowBackground.onRelease = function():Void{
this._parent.stopDrag();
};
More notes on this: KEY to array.. put them in an associative array
Associative Array, gets declared as an object
going to use the name of our linkage identifiers as the keys for our open windows associative array that ill assign to the keys the values of the mcs that are open...
add another line of code (oOpenWindows) then insert key and assign value of mcWindow which refers to the window that was just opened
simply added a new element to thte associative array you can then check to see if a element already exists in oOpenwindows with the same KEY as sLinkage... to see if it exists, check to see if it is NOT UNDEFINED...if it's not undefined that means you've already added it to the stage.. adding the return exits the function...
that code checks to see if the window is there, if it is, then it doesn't open again. BUT, the problem now is that if you close the windows you can't open them again...so you have to program that back in...
Need to tell Flash that it should remove the element from the associative array, mcCloseSquare.... add a delete statement, "delete operator" - removes the element from teh associative array - tells flash when you close that it removes the element from the associative array so that next time you try to add, the if statement will be false (it WILL be undefined... ouch my brain).
If you want to be anal:
function addWindow(sLinkage:String):Void {
if(oOpenedWindows[sLinkage] != undefined) {
// bring the current instance to the foreground
oOpenedWindows[sLinkage].swapDepths(nTopDepth);
return;
}
this makes it to where you can click on the button to swap depths in addition to clicking on the image.
Loading Movie Clip Content
You can load content into flash using action script, like Jpgs, etc. In order to do that you need to create a movie clip instance specifically for that purpose, you'll use "createEmptyMovieClip" - this creates a new movie clip instance with no information inside of it. This is for loading content.
this method is a method of the Movie Clip class which works for all classes including the main timeline. Syntax for example below: (instanceName, depth)
this.createEmptyMovieClip("mcHolder", this.getNextHighestDepth());
Listener?
Non progressive jpgs....... are the only kind you can load into Flash.
Comments (0)
You don't have permission to comment on this page.