If you have a movie clip on the stage with multiple objects inside of it:
(for example a square movie clip named boxContainer with smaller squares inside)
trace(boxContainer_mc.numChildren);
for (var i:int = 0; i<boxContainer_mc.numChildren; i++) {
var thechild = boxContainer_mc.getChildAt(i);
trace (thechild.name);
}
If the parent has a property, for example a boolean property that you want to change,
sometimes it can't find which parent you are referring to so you have to tell it like this:
nameParent(boxContainer_mc.getChildAt(i)).myProperty = true;
In this example boxContainer holds a bunch of boxes. Boxes has a boolen property (inside the Boxes.as file):
public var myProperty:Boolean = false;
In the main file:
Boxes(boxContainer_mc.getChildAt(i)).myPropery = true;
Thursday, September 1, 2011
Thursday, August 25, 2011
http://tbg.tonypa.pri.ee/tut05.html
http://www.tonypa.pri.ee/tbw/tut02.html
http://gamedev.michaeljameswilliams.com/2010/01/13/multidimensional-arrays-in-as3/
http://gamedev.michaeljameswilliams.com/2010/01/13/multidimensional-arrays-in-as3/
http://www.tonypa.pri.ee/tbw/tut02.html
http://www.emanueleferonato.com/2010/05/27/create-a-flash-game-like-talesworth-adventure/
http://www.emanueleferonato.com/2008/06/04/how-to-use-a-flash-game-tutorial-to-make-your-own-game/
http://gamedev.michaeljameswilliams.com/2009/06/01/use-flash-ide-as-level-editor/
http://www.tonypa.pri.ee/tbw/tut02.html
http://gamedev.michaeljameswilliams.com/2010/01/13/multidimensional-arrays-in-as3/
http://gamedev.michaeljameswilliams.com/2010/01/13/multidimensional-arrays-in-as3/
http://www.tonypa.pri.ee/tbw/tut02.html
http://www.emanueleferonato.com/2010/05/27/create-a-flash-game-like-talesworth-adventure/
http://www.emanueleferonato.com/2008/06/04/how-to-use-a-flash-game-tutorial-to-make-your-own-game/
http://gamedev.michaeljameswilliams.com/2009/06/01/use-flash-ide-as-level-editor/
Thursday, August 18, 2011
My Game
This is a 1 player game that could be expanded into a multi player game.
Theme:
You are an explorer stranded on a strange island. You must gather 3 treasures and escape from the island.
There is a grid-based playing field made up of tiles. Each tile may have a hidden treasure or have an important resource. On one side of the field on top of one of the tiles is a vicious beast-monster (bad guy). On the opposite side of the field is the player. The goal is to meet the win condition before the bad buy meets any number of various conditions (“bad guy” win conditions). The player is allowed to take 3 actions per turn.
Game Play:
The player takes a turn and then bad guy does his turn. If there are multiple players the bad guy takes a turn after every player turn.
Actions the bad guy might take:
Move a tile.
Make minions.
Destroy something.
Bad Guy Win Conditions:
The bad guy lands on the same tile as the player.
The bad guy overwhelms the grid with his minions.
The bad guy destroys your escape vessel.
Player actions:
Move 1 Space
Dig for treasure.
Build something (if they have enough resources)
Destroy and enemy minion.
Player(s) Win Condition:
The player(s) find at least 3 treasures and builds a boat make it off the island. If there are multiple players a bigger boat must be built.
The player has a meter that shows their total resource/money score. The meter increases when they find more resources either by uncovering them.
Thursday, August 11, 2011
In Class Notes
Inheritance
Pimp My Ride: They take a crappy car and make it fancy.
Instead of building a whole car from scratch they inherit a Nissan Sentra and extend it to look differently by changing it's properties.
It is still the same Nissan Sentra.
Composition
Composition is an alternative to inheritance.
This is like taking the Nissan Sentra and attaching another gadget, like a popcorn machine or huge cinema display. Making the 2 pieces work together, but they do not share any properties. You are composing the 2 pieces together.
Polymorphism
Allows objects of different classes to have the same method but behave differently.
On the Nissan Sentra when you turn on the lights that is a functionality of the car, but that method can turn on the headlights and turn on a disco ball. So "turnOn" can result in different things being turned on.
Pimp My Ride: They take a crappy car and make it fancy.
Instead of building a whole car from scratch they inherit a Nissan Sentra and extend it to look differently by changing it's properties.
It is still the same Nissan Sentra.
Composition
Composition is an alternative to inheritance.
This is like taking the Nissan Sentra and attaching another gadget, like a popcorn machine or huge cinema display. Making the 2 pieces work together, but they do not share any properties. You are composing the 2 pieces together.
Polymorphism
Allows objects of different classes to have the same method but behave differently.
On the Nissan Sentra when you turn on the lights that is a functionality of the car, but that method can turn on the headlights and turn on a disco ball. So "turnOn" can result in different things being turned on.
Thursday, August 4, 2011
Numbered Styled code
http://codeformatter.blogspot.com/2009/06/about-code-formatter.html
Notes from the Reading
Classes collect related functions (methods), variables (properties), and other relevant items.
Document Class
allows you to create a custom class that can be used as a type of timeline
replacement
Classpaths
To use a class in a
specific subdirectory, you need to import the class, including the classpath
Composition
aggregation
Composition says that an object can be composed of other objects, rather
than descend from other objects.
Document Class
allows you to create a custom class that can be used as a type of timeline
replacement
1: package {
2: import flash.display.MovieClip;
3: public class Main extends MovieClip {
4: public function Main() {
5: trace("Flash");
6: }
7: }
8: }
Classpaths
To use a class in a
specific subdirectory, you need to import the class, including the classpath
import flash.display.MovieClip;
import myapp.effects.Water;
import flash.events.*;
import myapp.effects.Water;
import flash.events.*;
package myapp.effects {
public class Water {
public function Water() {
}
}
}
public class Water {
public function Water() {
}
}
}
Composition
aggregation
Composition says that an object can be composed of other objects, rather
than descend from other objects.
OOP
Knowing when to opt for an object-oriented model depends largely on
understanding the benefits of OOP, among them:
Classes. Classes are collections of related functions and variables gathered
to facilitate one or more specific goals. They are the foundation of
OOP, and we’ll look at a few ways to use them.
Inheritance. Inheritance is one of OOP’s greatest sources of power, as it
allows you to add functionality to an existing feature set without reinventing
the wheel, as the saying goes. Being able to extend an existing class to
create a subclass, rather than originating an entirely new class, can save
you a significant amount of time and labor, as well as improve project
design.
Composition. Inheritance isn’t appropriate for every situation, and composition
is often a useful alternative. Composition is a technique somewhat
akin to collecting related classes, much like classes collect related
functions and variables. The classes do not inherit characteristics from
one another, but are made to work together in productive ways.
Encapsulation. It’s usually not a good idea to expose all aspects of a class
to other classes or the surrounding application. Encapsulation isolates
most elements of a class from the outside world, allowing only a select
few elements, if any, to be seen by structures that use the class.
Polymorphism. Polymorphism allows objects of different classes to have,
through a unified interface design, methods that have the same name but
that behave differently when invoked. By using polymorphism, you can
reduce the number of methods that must be documented and learned,
and, more importantly, make it easier to extend classes. New subclasses
can use an existing method name but return a result appropriate to the
new class.
To get started you open:
ActionScript Class.
You name it with a capital letter.
For example: Main
Save it.
Next you open a regular action script file.
Save it in the same folder as your Main.as
Then in the properties panel you give it a class of Main.
For a document class you have to give it a timeline.
package {
import flash.display.MovieClip;
public class Main extends MovieClip { //you dont have to extend from something, but we are using a document class.
//you have to extend a mc with the document class because we need a timeline
//if you were making a sprite for example you do need a timeline
public function Main() {
// constructor code
trace("hello world");
}
}
And then a bunch of shit happened that I should probably have notes on.
understanding the benefits of OOP, among them:
Classes. Classes are collections of related functions and variables gathered
to facilitate one or more specific goals. They are the foundation of
OOP, and we’ll look at a few ways to use them.
Inheritance. Inheritance is one of OOP’s greatest sources of power, as it
allows you to add functionality to an existing feature set without reinventing
the wheel, as the saying goes. Being able to extend an existing class to
create a subclass, rather than originating an entirely new class, can save
you a significant amount of time and labor, as well as improve project
design.
Composition. Inheritance isn’t appropriate for every situation, and composition
is often a useful alternative. Composition is a technique somewhat
akin to collecting related classes, much like classes collect related
functions and variables. The classes do not inherit characteristics from
one another, but are made to work together in productive ways.
Encapsulation. It’s usually not a good idea to expose all aspects of a class
to other classes or the surrounding application. Encapsulation isolates
most elements of a class from the outside world, allowing only a select
few elements, if any, to be seen by structures that use the class.
Polymorphism. Polymorphism allows objects of different classes to have,
through a unified interface design, methods that have the same name but
that behave differently when invoked. By using polymorphism, you can
reduce the number of methods that must be documented and learned,
and, more importantly, make it easier to extend classes. New subclasses
can use an existing method name but return a result appropriate to the
new class.
To get started you open:
ActionScript Class.
You name it with a capital letter.
For example: Main
Save it.
Next you open a regular action script file.
Save it in the same folder as your Main.as
Then in the properties panel you give it a class of Main.
For a document class you have to give it a timeline.
package {
import flash.display.MovieClip;
public class Main extends MovieClip { //you dont have to extend from something, but we are using a document class.
//you have to extend a mc with the document class because we need a timeline
//if you were making a sprite for example you do need a timeline
public function Main() {
// constructor code
trace("hello world");
}
}
And then a bunch of shit happened that I should probably have notes on.
Thursday, July 28, 2011
Timer
import flash.utils.Timer;
//TIMER EVENTS
//You have one handler for every listener.
//The enter frame event is based on the frame rate of the movie.
//Timer event is not connected to the rate of the movie, it is based on time.
//Start by creating an instance of our timer and store it in a variable.
var theTimer:Timer = new Timer(50); //Timer class takes 2 parameters.
//delay, repeat count (optional)
//If you don't include the count the default is 0. 0= forever.
theTimer.start();
//event listeners
theTimer.addEventListener(TimerEvent.TIMER, onTimer); //onTimer is the name of the event listener
// event handlers
function onTimer(event:TimerEvent):void { //inside the parenthesis is the variable that passes the event handler.
//.TimerEvent is the data class (we use the same as above)
trace("timer");
//myRectangle01_mc.x +=10; //moves it every second to the right
hourHand01_mc.rotation +=360/(60*60*12);
minuteHand01_mc.rotation +=360/(60*60);
secondHand01_mc.rotation +=360/60; // = 6 degrees
}
Review
import flash.events.KeyboardEvent;
import flash.utils.Timer;
/*
INTERMEDIATE AUTHORING
WEEK 2
*/
// CUSTOM OBJECTS
var plane:Object = new Object(); // creates a new object
plane.x = 200;
plane.y = 300;
plane.pitch = 0;
plane.roll = 5;
plane.yaw = 5;
trace(plane.roll);
// PROPERTIES
// POSITION
square01_mc.x = 100;
square01_mc.y = 300;
// SIZE (#1)
//square01_mc.width = 40;
//square01_mc.height = 40;
// SIZE (#2)
square01_mc.scaleX = .5; // scales using decimals between 0 and 1
square01_mc.scaleY = .5;
//square01_mc.scaleX = square01_mc.scaleY = .5; // one-line shortcut for setting
// the same value to multiple properties
// TRANSPARENCY
square01_mc.alpha = .75;
// ROTATION
square01_mc.rotation = 45; // sets the rotation to 45 degrees
square01_mc.rotation += 15; // adds 15 degrees to the current value
square01_mc.rotation -= 45; // rotate 45 degrees CCW
// EVENT LISTENERS
// MOUSE EVENTS
square01_mc.addEventListener(MouseEvent.CLICK, onClick);
square02_mc.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent):void {
//square01_mc.rotation += 15;
event.target.rotation -= 15;
}
// KEYBOARD EVENTS
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeypress);
function onKeypress(event:KeyboardEvent):void {
trace(event.keyCode);
switch(event.keyCode) {
case 38:
trace("up")
square02_mc.y -= 10;
break;
case 37:
trace("left");
square02_mc.x -= 10;
break;
case Keyboard.DOWN:
trace("down")
square02_mc.y += 10;
break;
case Keyboard.RIGHT:
trace("right");
square02_mc.x += 10;
break;
}
}
// TIMER EVENTS
var theTimer:Timer = new Timer(1000,5); // delay in milliseconds, repeat count (zero = forever)
theTimer.addEventListener(TimerEvent.TIMER,onTimer);
theTimer.start();
function onTimer(event:TimerEvent):void {
trace("Timer");
}
// ENTER FRAME EVENT
stage.addEventListener(Event.ENTER_FRAME, onFrameLoop);
function onFrameLoop(event:Event):void {
square01_mc.rotation += 20;
}
Thursday, July 14, 2011
Review
Variables:
Containers for data.
Cannot start with a number.
Camel casing.
Cannot be protected words.
Give it a unique name.
Tell it what class of data you want it to store:
Numbers, String, Boolean, Integer, Unsigned Integer, Arrays
var myFirstVariable:Number = 250.5 //any number including decimals
var myInteger:int = 36; //any whole number that is positive or negative
var myUnsignedInteger:uint = 2000; //any positive whole number
var myString:String = "Hello World"; //just plain text
var myBoolean:Boolean = true; //true or false; 1 or 0;
Arrays:
var myFirstArray:Array = new Array(); //creates a new empty array
myFirstArray[0] = "Ross";
myFirstArray[1] = "Higgins";
myFirstArray[2] = 36;
trace(myFirstArray); // send the values of the array to the output panel
Condensed Way to Make an Array:
var mySecondArray:Array = ["Ross", "Higgins", 36];
.push
mySecondArray.push("Married"); //PUSH adds a value to the end of existing array
.pop
mySecondArray.pop(); //POP takes the last one off
.splice
mySecondArray.splice(1,0,"California"); //SPLICE adds a value to the array in a specified position
mySecondArray.splice(1,1); //the position, number of items we are removing
.length
trace("length:" + mySecondArray.length);
OUT PUT:
length:3
HELP:
highlight one of the blue words, like Array, and right click then select View Help
Operators:
== equality operator
> greater than
< less than
>= greater than or equal to
<= less than or equal to
! not operator
!= not equal to
!> greater than
% modulus operator (returns the remainder of the divsion of 2 numbers)
10 % 3 = 1 //10 divide by 3 over and over until it can no longer divide and it gives you the remainder
25 % 5 = 0 //you can use this to check if your array has even values
&& and operator
|| operator
++ increment operator
-- decrement operator
Conditional Statements:
//IF STATEMENTS
if ( myInteger == 362) {
trace("the first statement is true");
} else if (myFirstVariable = 300) {
trace("the second statement is true");
} else {
trace("everything else is false");
}
//AND OPERATOR
if (myInteger == 36 && myString == "Hello") {
trace("both conditions are true");
}
//OR OPERATOR
if (myInteger == 36 || myString == "Hello") {
trace("at least one of the conditions are true");
}
//SWITCH STATEMENTS
var a:Number = 35;
switch(a) {
case 0:
trace("#1");
break; //if you don't have break then it will continue tracing everything below the match
case "Hello World":
trace("#2");
break;
case 35:
trace("#3");
break;
default:
trace("nothing else was a match");
}
Loops:
//FOR LOOPS
//For loops are finite in their execution
//There are 3 parts in constructing Loops :
set up a variable, condition, incrimentor
for(var i:int = 0; i < 5; i++) {
trace("Hello");
}
OUT PUT:
Hello
Hello
Hello
Hello
Hello
//counting up
for(var j:int = 0; j < 10; j++) {
trace(j);
}
OUT PUT:
0
1
2
3
4
5
6
7
8
9
//counting down
for(var k:int = 4; k > 0; k--) {
trace(k);
}
OUT PUT:
4
3
2
1
//WHILE LOOPS
//ends when the condition is met (can create an infinite loop)
var theNumber:Number = 0;
while (theNumber < .5) {
theNumber = Math.random(); //u do this so you don't get infinite loop.
// Math.random will pick numbers above and below .5
trace(theNumber);
}
Random Numbers:
Math.random
Math.random(); //picks a number between 0 - 1; never 0 or 1;
var theRandomNumber:Number = Math.random();
trace(theRandomNumber);
theRandomNumber = Math.random() *5;
trace(theRandomNumber);
rounding
Math.round(); //like elementary school; >= .5 rounds up; < .5 rounds down
Math.ceil(); //always rounds up
Math.floor(); //always rounds down
//(you have to pass a number into the parenthesis to make the above work) Math.round(33);
theRandomNumber = Math.ceil(Math.random() * 100); //pick a random number between 1-100
Functions
1.
function showMessage():void {
}
//void is it's data class. Because we are not returning a value out of the function.
trace("Hello");
}
showMessage();
//call the function
3.
function showMessage(theMessage):void {
trace(theMessage);
}
showMessage("This is Stuff");
showMessage("Hello World");
Containers for data.
Cannot start with a number.
Camel casing.
Cannot be protected words.
Give it a unique name.
Tell it what class of data you want it to store:
Numbers, String, Boolean, Integer, Unsigned Integer, Arrays
var myFirstVariable:Number = 250.5 //any number including decimals
var myInteger:int = 36; //any whole number that is positive or negative
var myUnsignedInteger:uint = 2000; //any positive whole number
var myString:String = "Hello World"; //just plain text
var myBoolean:Boolean = true; //true or false; 1 or 0;
Arrays:
var myFirstArray:Array = new Array(); //creates a new empty array
myFirstArray[0] = "Ross";
myFirstArray[1] = "Higgins";
myFirstArray[2] = 36;
trace(myFirstArray); // send the values of the array to the output panel
Condensed Way to Make an Array:
var mySecondArray:Array = ["Ross", "Higgins", 36];
.push
mySecondArray.push("Married"); //PUSH adds a value to the end of existing array
.pop
mySecondArray.pop(); //POP takes the last one off
.splice
public splice(startIndex:Number, [deleteCount:Number], [value:Object]) : Array
mySecondArray.splice(1,0,"California"); //SPLICE adds a value to the array in a specified position
mySecondArray.splice(1,1); //the position, number of items we are removing
.length
trace("length:" + mySecondArray.length);
OUT PUT:
length:3
HELP:
highlight one of the blue words, like Array, and right click then select View Help
Operators:
== equality operator
> greater than
< less than
>= greater than or equal to
<= less than or equal to
! not operator
!= not equal to
!> greater than
% modulus operator (returns the remainder of the divsion of 2 numbers)
10 % 3 = 1 //10 divide by 3 over and over until it can no longer divide and it gives you the remainder
25 % 5 = 0 //you can use this to check if your array has even values
&& and operator
|| operator
++ increment operator
-- decrement operator
Conditional Statements:
//IF STATEMENTS
if ( myInteger == 362) {
trace("the first statement is true");
} else if (myFirstVariable = 300) {
trace("the second statement is true");
} else {
trace("everything else is false");
}
//AND OPERATOR
if (myInteger == 36 && myString == "Hello") {
trace("both conditions are true");
}
//OR OPERATOR
if (myInteger == 36 || myString == "Hello") {
trace("at least one of the conditions are true");
}
//SWITCH STATEMENTS
var a:Number = 35;
switch(a) {
case 0:
trace("#1");
break; //if you don't have break then it will continue tracing everything below the match
case "Hello World":
trace("#2");
break;
case 35:
trace("#3");
break;
default:
trace("nothing else was a match");
}
Loops:
//FOR LOOPS
//For loops are finite in their execution
//There are 3 parts in constructing Loops :
set up a variable, condition, incrimentor
for(var i:int = 0; i < 5; i++) {
trace("Hello");
}
OUT PUT:
Hello
Hello
Hello
Hello
Hello
//counting up
for(var j:int = 0; j < 10; j++) {
trace(j);
}
OUT PUT:
0
1
2
3
4
5
6
7
8
9
//counting down
for(var k:int = 4; k > 0; k--) {
trace(k);
}
OUT PUT:
4
3
2
1
//WHILE LOOPS
//ends when the condition is met (can create an infinite loop)
var theNumber:Number = 0;
while (theNumber < .5) {
theNumber = Math.random(); //u do this so you don't get infinite loop.
// Math.random will pick numbers above and below .5
trace(theNumber);
}
Random Numbers:
Math.random
Math.random(); //picks a number between 0 - 1; never 0 or 1;
var theRandomNumber:Number = Math.random();
trace(theRandomNumber);
theRandomNumber = Math.random() *5;
trace(theRandomNumber);
rounding
Math.round(); //like elementary school; >= .5 rounds up; < .5 rounds down
Math.ceil(); //always rounds up
Math.floor(); //always rounds down
//(you have to pass a number into the parenthesis to make the above work) Math.round(33);
theRandomNumber = Math.ceil(Math.random() * 100); //pick a random number between 1-100
Functions
1.
function showMessage():void {
}
//void is it's data class. Because we are not returning a value out of the function.
2.
function showMessage():void {trace("Hello");
}
showMessage();
//call the function
3.
function showMessage(theMessage):void {
trace(theMessage);
}
showMessage("This is Stuff");
showMessage("Hello World");
//pass the information inside the var theMessage into the function
4. Converting to Farenheit
function celciusToFarenheit(theCelciusNumber):Number {
return(9/5) * theCelciusNumber + 32;
}
var theTemperature:Number = celciusToFarenheit(28);
trace(theTemperature);
return(9/5) * theCelciusNumber + 32;
}
var theTemperature:Number = celciusToFarenheit(28);
trace(theTemperature);
HOMEWORK:
Read Chapter 1 & 2
Subscribe to:
Posts (Atom)