This is my tutioral to make mc objects stop from moving and go through walls...first if you don't have the movement scripts... copy and paste on a notepad or something, heres the code:
onClipEvent(enterFrame) {
if(Key.isDown(Key.RIGHT)) {
this._x += 6;
}
}
onClipEvent(enterFrame) {
if(Key.isDown(Key.LEFT)) {
this._x -= 6;
}
}
onClipEvent(enterFrame) {
if(Key.isDown(Key.UP)) {
this._y -= 6;
}
}
onClipEvent(enterFrame) {
if(Key.isDown(Key.DOWN)) {
this._y += 6;
}
}
Now,you can have a scripts from stopping a mc objects from ging trough a drawn wall....
on the next reply...
Stop a mc moving objects from going through walls! [Flash][Actionscript]
Started by: cashleycool | Replies: 25 | Views: 2,697
Jun 27, 2007 8:48 AM #41233
Jun 27, 2007 8:50 AM #41235
I shall tell you how to do..now!
First of all, you need to make your wall. Make sure it is 50 pixels wide. Mine is just two rectangles with a gap of 220 pixels between them vertically. Each rectangle is 250 in height. If you use those dimensions this tutorial will be easier, since you wont have to change the code at all. Make them a MC (Movieclip) and delete the MC from the stage. (Both the rectangles should be in the same MC).
Now, open the library (Ctrl+L or Windows>Library) and you should see the MC you just made. Right Click on it and then go to ‘Linkage…’.
Now we can put our MC on the stage with actionscript by using the attachMovie() function. Enter this code onto the frame.
Code (actionscript)
var wallY:Number = 475;
createEmptyMovieClip("holder", getNextHighestDepth());
for (i=0; i<200; i++) {
holder.attachMovie("walls", "wall"+i, i);
_root.holder["wall"+i]._x = i*50;
_root.holder["wall"+i]._y = wallY;
if (wallY>550) {
down = true;
}
if (wallY<400) {
down = false;
}
if (down) {
wallY -= 50;
} else {
wallY += 50;
}
}
If you tested your movie now (Ctrl+Enter) you would find that you would have the wall on your stage, and that it covers the whole stage length and changes heights. It doesn’t move with the arrow keys yet, I will show you how to do that later. But for know I will explain the code you just got.
Line 1: This is just declaring a variable called wallY. This is going to tell the wall what its _y coordinates should be.
Line 2: This is creating an empty movie clip called holder. All the wall MC’s that are placed on the stage will be held in here, so when it comes to moving them we can just move holder instead of having to use a for statement. This stops flash from lagging a bit.
Line 3: This is where all the magic happens. It is a for statement, that will keep running until ‘i’ isn’t less than 200. Therefore following code will 200 times.
Lines 4-6: Here we are attaching the ‘wall’ MC to the stage. You should see that the code is holder.attachMovie(”wall… That means we are attaching it inside the holder MC. We are also declaring the walls _x and _y coordinates. The _x coordinates is i*50, so basically it increases by 50 pixels each time. The _y is equal to the wallY variable.
Lines 7-17: All of these lines are determining the walls height. 7-12 are seeing if the walls should move up or down. 12-17 are then making the wallY variable increase or decrease depending on what 7-12 came up with.
Now, if you enter this code beneath the code I just gave you your walls should move with the arrow keys.
Code (actionscript)
onEnterFrame = function () {
if (Key.isDown(Key.RIGHT)) {
holder._x -= 5;
} else if (Key.isDown(Key.LEFT)) {
holder._x += 5;
}
};That is pretty simple. The first line means ‘Everytime this frame is entered’. So the code after that will happen every frame. Unlike the previous you just got, which will only happen once.
The rest of the frames are what makes the walls move. if(Key.isDown(Key.RIGHT)){ is an if statement that is checking is the right arrow key is pressed. If it is than the holder MC’s _x coordinates is told to decrease by 5 pixels. That will make it move left, but appear as if you are traveling right. The next part says ‘if the right arrow key isnt pressed, and the left one is make the holder MC move right’.
Helpfull?????:heh:
First of all, you need to make your wall. Make sure it is 50 pixels wide. Mine is just two rectangles with a gap of 220 pixels between them vertically. Each rectangle is 250 in height. If you use those dimensions this tutorial will be easier, since you wont have to change the code at all. Make them a MC (Movieclip) and delete the MC from the stage. (Both the rectangles should be in the same MC).
Now, open the library (Ctrl+L or Windows>Library) and you should see the MC you just made. Right Click on it and then go to ‘Linkage…’.
Now we can put our MC on the stage with actionscript by using the attachMovie() function. Enter this code onto the frame.
Code (actionscript)
var wallY:Number = 475;
createEmptyMovieClip("holder", getNextHighestDepth());
for (i=0; i<200; i++) {
holder.attachMovie("walls", "wall"+i, i);
_root.holder["wall"+i]._x = i*50;
_root.holder["wall"+i]._y = wallY;
if (wallY>550) {
down = true;
}
if (wallY<400) {
down = false;
}
if (down) {
wallY -= 50;
} else {
wallY += 50;
}
}
If you tested your movie now (Ctrl+Enter) you would find that you would have the wall on your stage, and that it covers the whole stage length and changes heights. It doesn’t move with the arrow keys yet, I will show you how to do that later. But for know I will explain the code you just got.
Line 1: This is just declaring a variable called wallY. This is going to tell the wall what its _y coordinates should be.
Line 2: This is creating an empty movie clip called holder. All the wall MC’s that are placed on the stage will be held in here, so when it comes to moving them we can just move holder instead of having to use a for statement. This stops flash from lagging a bit.
Line 3: This is where all the magic happens. It is a for statement, that will keep running until ‘i’ isn’t less than 200. Therefore following code will 200 times.
Lines 4-6: Here we are attaching the ‘wall’ MC to the stage. You should see that the code is holder.attachMovie(”wall… That means we are attaching it inside the holder MC. We are also declaring the walls _x and _y coordinates. The _x coordinates is i*50, so basically it increases by 50 pixels each time. The _y is equal to the wallY variable.
Lines 7-17: All of these lines are determining the walls height. 7-12 are seeing if the walls should move up or down. 12-17 are then making the wallY variable increase or decrease depending on what 7-12 came up with.
Now, if you enter this code beneath the code I just gave you your walls should move with the arrow keys.
Code (actionscript)
onEnterFrame = function () {
if (Key.isDown(Key.RIGHT)) {
holder._x -= 5;
} else if (Key.isDown(Key.LEFT)) {
holder._x += 5;
}
};That is pretty simple. The first line means ‘Everytime this frame is entered’. So the code after that will happen every frame. Unlike the previous you just got, which will only happen once.
The rest of the frames are what makes the walls move. if(Key.isDown(Key.RIGHT)){ is an if statement that is checking is the right arrow key is pressed. If it is than the holder MC’s _x coordinates is told to decrease by 5 pixels. That will make it move left, but appear as if you are traveling right. The next part says ‘if the right arrow key isnt pressed, and the left one is make the holder MC move right’.
Helpfull?????:heh:
sticknewyork
Posts: 0
Joined: Sep 2025
Posts: 0
Joined: Sep 2025
Jun 27, 2007 11:54 PM #41374
too hard i give up well its not too hard im just lazy
Jun 29, 2007 7:46 AM #41658
I'll have to try it out when I get my flash comp back in working condition but sounds hopeful [I just skimmed]
Mooper
Posts: 0
Joined: Sep 2025
Posts: 0
Joined: Sep 2025
Jul 1, 2007 6:27 AM #42072
brain hurting ah too hard for me beginner ow my head is steaming i tried it but i couldn't understand it. But great tut for more advanced people.
Jul 1, 2007 6:31 AM #42073
You totally just copy-pasted that, I have never seen you type with such grammar, and I know for a fact that you aren't smart enough to figure this out yourself.
*reported*
*reported*
Jul 5, 2007 3:05 PM #43072
Quote from JawzYou totally just copy-pasted that, I have never seen you type with such grammar, and I know for a fact that you aren't smart enough to figure this out yourself.
*reported*
ouch...i'm 19 :heh: :heh: :heh:
Quote from Mooperbrain hurting ah too hard for me beginner ow my head is steaming i tried it but i couldn't understand it. But great tut for more advanced people.
Thank you, Jawz is a Radical. So try the script!
Jul 6, 2007 9:13 AM #43269
What the **** does your age have to do with anything?
You're a ****ing retard.
You're a ****ing retard.
Jul 6, 2007 10:20 AM #43280
Quote from JawzWhat the **** does your age have to do with anything?
You're a ****ing retard.
LOL no fevegartgarstgvwrstbgvwdfvbrthbg
Jul 7, 2007 2:13 AM #43377
You didn't even answer my ****ing question you tool.
Jul 7, 2007 11:12 AM #43463
Quote from JawzYou didn't even answer my ****ing question you tool.
You know matt2k7 doesn't likes you?:Spiderman:
And answer will be answer later
Jul 7, 2007 11:32 AM #43470
I don't ****ing give a shit if some noob called matt2k7 likes me.
God you're a ****ing noob.
God you're a ****ing noob.
Jul 7, 2007 11:40 AM #43472
Quote from JawzI don't ****ing give a shit if some noob called matt2k7 likes me.
God you're a ****ing noob.
True, i got his msn
Jul 7, 2007 11:42 AM #43473
I don't care if you have his msn either.
****ing hell.
****ing hell.
Jul 7, 2007 11:50 AM #43475
Quote from JawzI don't care if you have his msn either.
****ing hell.
He made spp now u know......anyway why making those short madness?