Pages

Friday 23 September 2011

Flash ActionScript 3.0

At college we have begun learning some AS 3.0 in Flash, as opposed to the 2.0 we learned last year. We have learnt some basic functions including importing movie clips/bitmap images to the stage, and code to create a 'drag and drop' style game.

The advantages of using AS 3.0 is that you generally have more control over functions and it runs quicker. Furthermore there is more demand for people who can use AS 3.0 in today's interactive media industry. What is also helpful is that there seems to be so many more online tutorials concerning AS 3.0 as opposed to AS 2.0, I'm sure this will come in handy in the near future. Although ActionScript 3.0 is a harder language to learn than 2.0, I believe the benefits of using 3.0 will make using 2.0 somewhat pointless, in my opinion. I have used AS 2.0 for around a year now and I think this was a great way to get into flash, but to make some more complex applications AS 3.0 is definately necissary.

Here is some of what I have learned in todays lectures concerning ActionScript 3.0, I will explain what each part of the code means as I run through it:

var mc:MovieClip= new MovieClip();

This means that we are creating a new variable called 'mc'. And this variable can hold movie clips (A type of symbol used in Flash.). Then, it creates a new movie clip which we use in a little while.


mc.graphics.beginFill(0xFF0000);

This line of code firstly specifies what variable we are dealing with, this is 'mc', the variable we created earlier. Then it is telling it to set a colour to any graphics that are drawn. The colour set is the part in brackets, '(0xFF0000). This is what is called a hex colour code. This particular code is for a red colour, every colour you can see on your screen has a hex code, so to change it you simply change the colour code.


mc.graphics.drawCircle(50,50,50);

After setting the colour, we tell our variable 'mc' to actually draw a graphic shape. In this case it is a circle. Also we can see three numbers in the brackets being shown, '(50,50,50);'. The first two numbers set what is called the 'reference point'. This is the shape's point of origin, but just for drawing shapes it is not too important, but if you set the shapes position on the stage it will be relative to it's reference point. The third number inside the brackets refers to the size of this particular shape. Because this is a circle, we only need one number to specify it's size. If we used another shape such as a rectangle (drawRect) then we would need two numbers which in essence set the width and height of the shape.


mc.graphics.endFill();

This will stop the shape from continuing to be filled. Unless you have other functions in your project, this is not too important.


mc.x=80;
mc.y=50;

This tells the variable 'mc' including our circle shape to go to a set position on the stage, in this case, x = 80 and y = 50.


addChild(mc);

 Finally and perhaps most importantly, this line of code will actually put 'mc' on the stage when it is run, and this will draw our circle.

No comments:

Post a Comment