FLASH

Excercise 1

Last modified on 2009-01-10 15:29:20 GMT. 1 comment. Top.

In this exercise, i am learning about mouse events and functions, how to move a object with a mouse click . I have chosen to move the object (square) up 25 and sideways 10 with a rotation of 11 degrees. now i no this in my next one i am going to see if i can make muliple objects move on the stage :)
(Wish me luck)……

Square_mc.addEventListener(MouseEvent.CLICK, onclick);

function onclick(event:MouseEvent):void

{
event.target.x += 10
event.target.y += -25
event.target.rotation += -11;
}
Square_mc.buttonMode = true;

more to coming soon ..

Exercise 1 part 2

Last modified on 2009-01-16 16:07:26 GMT. 2 comments. Top.

After my last exercise I have been playing with the Mouse events, trying to get multiple objects to move around the stage.
Just by repeating the exercise 1 code and changing the movie clips names. also on this stage I have one of the object move in a different way.
I used a RollOver event. This makes the object move as the cursor goes over it.

Here is the code.

Square_mc.addEventListener(MouseEvent.ROLL_OVER, onRoll);
function onRoll(event:MouseEvent):void
{
event.target.x += 10
event.target.y += -25
event.target.rotation += -11;
}
Square_mc.buttonMode = true;
Tri_mc.addEventListener(MouseEvent.CLICK, onclicked);
function onclicked(event:MouseEvent):void
{
event.target.x += -5
event.target.y += 20
event.target.rotation += -10;
}
Tri_mc.buttonMode = true;
Str_mc.addEventListener(MouseEvent.CLICK, onclick2);
function onclick2(event:MouseEvent):void
{
event.target.y += -10
event.target.x += -10
event.target.rotation += -11
}
Str_mc.buttonMode = true;
Square2_mc.addEventListener(MouseEvent.CLICK, onclick3);
function onclick3(event:MouseEvent):void
{
event.target.x += 10
event.target.y += -40
event.target.rotation += -11;
}
Square2_mc.buttonMode = true;

In the next exercise I will be learning about keyboard events and how make object move by using the KEY_UP and KEY_DOWN properties.
also going to try making a return code for the Roll_Over event.
:)

Once again wish me luck…..

Update and Explanation.

Last modified on 2009-11-20 09:03:29 GMT. 8 comments. Top.

well I have been looking at my own blog exercise 1 and I have come to the conclusion that I did not explain the code in any shape or form and for me to show u what I have learned and hopefully help others understand a little more of what goes in flash coding, I have broken the code down a bit..

“Square_mc” This is the name I gave to the object on the stage. This is called the instance name. Also I used _mc to let me no it’s a movieclip. all objects on the stage need to have a instance to be called up in the code, there is Three symbol types Movieclip _mc, Button _bt and Graphic _gc , this also can make it easier to read the code at a later date.

The “addEventListener” is the way we tell flash to listen for an event. After this we have to let flash know what this event will be, in this it was a “MouseEvent”.

“MouseEvent.CLICK” is really as it says; the event will be a click event so as You press down on the mouse button the event will start.

we then give the event a name, in this I call it “onclick”, this could have been anything but it good to put something in relation to what you want to happen, also to make it easier for you to come back to it at a later date.

With “onclick” now the name of the function that will run, we have to let flash know what will be carried out once the item as been clicked on.

The “:void” part of the code is there to let the program know that we do not need a return a value from the event.

When the “square_mc” is clicked the object will then move up by 10 pixels ” x += 10″ and across 25 pixels y “+= -25″ with a rotation of 11 degrees “rotation += -11″ I put these value in by random they could have been anything.

Then at the end of this program there is “Square_mc.buttonMode = true;” which tells flash to treat “Square_mc” like a button, so when the cursor goes over the object it will show that the item is clickable.

Well that’s it, if you now go to the second exercise and read throw the code, I hope this would have given a better understanding of what’s going on in each part.

Thank you for reading …

Keyboard Events

Last modified on 2009-03-05 13:07:15 GMT. 1 comment. Top.

Here we go finally,

Only a small exercise due to most of the code is the same as the last few exercises, so in this One there was not much for me to try to remember :)

so first off in this we have to make the ” EventListener ” listen to the stage for an event, the reason for this is if we call up the instance name, like I did on the other codes, we would have to select the item before it would move, so if we make the whole stage active the listen will find the Object without us having to click on it.
Here we will be using Key_Down (press) and the Key_Up (release)
I have chosen to make the item jump as we press the button and on release the item will return to position.

Here is the code…

stage.addEventListener(KeyboardEvent.KEY_DOWN, jump);
stage.addEventListener(KeyboardEvent.KEY_UP, land);

//stage listener so we dont have to select Object

function jump(event:KeyboardEvent):void
{
Man_mc.y -= 100;
}
//jump up 100 pixels

function land(event:KeyboardEvent):void
{
Man_mc.y += 100;
}
/*man drop back to the original
place which is down 100 pixels*/

To test this flash movie please click in box first or click this link.
TESTMAN


I would like to add that if u hold down space bar the object (the man) will fly off screen. This is because the drop down is a listener, soon I will be learning how to make it return to its position and not run away.

Thank you for reading

Next it will be timer event…

Share and Enjoy:
  • Twitter
  • Facebook
  • Google Bookmarks
  • Print
  • del.icio.us
  • RSS
  • email
  • Digg
  • StumbleUpon
  • Live
  • Ping.fm
  • Slashdot
  • MySpace

Trackback URL for this entry