Thursday, October 16, 2008

Notes Class 2 September 17, 2008

7. packages.
Packages. A way of putting classes insubfolders instead of using them in the root folder.

Need to follow a path using dot notation.


Functions, loops and conditionals.


Call the function, use the parenthesis. Function always has parenthesis. When you invoke a function, it runs the function then comes back under the function and runs the rest of the code. You can call a function as often as you like by calling their name.

A function does something for you. Draw screen. Setup an interface. Etc. not so interesting to run on its own. You can hand it things to do. It can be like a factory.

9. functions 2
Use variables so you can change numbers over time. Addnumbers function requires 2 arguments for the function so you have to send it 2. numbers are separated by numbers. Each time the function runs it is fresh. Variables only last for the life of the function then the memory is cleared. They are not stored in memory. The numbers have “local scope” only alive within the function.

Variables above function are available always. Inside function only available to the function. Outside function all functions can see it. Inside function only the function can see it. Think of them as global variables – all fucnctions can see it. Private variables are available within a class. Public variables are available to all classes.


10. functions 3

Has a Main class and another_class sub class

To create another_class it will need 2 pieces of data. Can think of classes as a factory just as you can think of functions as a factory to pass data into it.



11, black boxes

Use “this” to refer to itself. With this we don’t need to use the library to add a box any more. This method is faster, faster, faster than using library elements and uses less memory.

graphics.beginFill(0x000000)
grapics.drawRect(0,0,box_width,box_height);
graphics.endFill()


addChild = add object to the stage.



Anything in a document class it needs to be a movieclip. Except for document class, you don’t need to use movieclips.
Shapes a surface we can draw on. Use very little memory
Sprite we can draw on, make it interactive and give it children. A little bigger than shapes but not as large as movie clips and can add interaction.
Movie clips bigger than the others.

Black box, as a child of the class gets all the properties that the sprite or shape can contain.



The screen never redraws in the middle of a function. It always redraws after all the code is done, at the end of the function.



15. loops

Var i:int =0;
I < 10;
I++


Using i because it lasts for a second.





It would be a good thing to diagram the structure of how flash works with the public and private variables, and how it reads / uses functions and methods.



A conditional is a statement that checks that the for loop is true or false. Or you could say, the for loop checks for a condition within the for loop.

== means “if they are the same.
= means put the number into the variable

if ( i == 7 ) means if they are the same

if ( i=!7 ) means if it’s not equal to the number



public function my_class()
{
trace("Hi. Lets try out a loop");


// this is a "for" loop
for(var i:int = 0; i < 10; i++) // three parts. One sets up the variable. One sets the condition. One tells the loop how to increment.
{

// this is an if statement inside the for loop
if (i == 7) { // note the brackets
trace("Magic number 7 found!");
} else {
trace("Current value of i -> " + i);
}
}

}




The above code is the same as in number 17 but it’s using something I forget



21 patterns
Is like you would make an image gallery in css for a web site.


% = modulo operator. Tells you if you take number on right side and divide into number on the left side this is the remainder.

Multiplication in flash is a lot faster than division. So a height / width times .5 is better than divide by 2.


Modulo, nested loops for making 6 patterns.


Draw shapes with the drawing api or put things in the library. Can put phtotgraphs in the library. Pattens don’t need to repeat, they can evolve.


Add to constructor use a uintiger new_color:uint then add in box = new black_box ( , , 0xffffff)


0x is the same thing as the # in html, css

No comments: