# Editting code from movieclip to actions layer

**URL:** <https://forum.kirupa.com/t/editting-code-from-movieclip-to-actions-layer/301325>\
**Category:** flash\
**Created:** [December 7, 2009, 7:48pm UTC](https://forum.kirupa.com/t/editting-code-from-movieclip-to-actions-layer/301325 "2009-12-07T19:48:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iakona](https://avatars.discourse-cdn.com/v4/letter/i/bbe5ce/32.png) [@Iakona](https://forum.kirupa.com/u/Iakona)\
**Post date:** [December 7, 2009, 7:48pm UTC](https://forum.kirupa.com/t/editting-code-from-movieclip-to-actions-layer/301325/1 "2009-12-07T19:48:51Z")

</div>

Hey chaps i’m currently having a small problem with some Actionscript 2.0 in CS3.

I’m following a tutorial to make a simple maze like game  
Tutorial here: [http://www.webwasp.co.uk/tutorials/b32-collision-detection/01.php](http://www.webwasp.co.uk/tutorials/b32-collision-detection/01.php)

I’m currently at step 5 where it’s coding the movement and wall detection… The problem is the tutorial wants me to apply the code directly to the maze/wall movieclip. However as this is for a college project my lecturer will not accept actionscript directly applied to buttons or movieclips… He basically wants all the script on a seperate actionscript layer. So basically what i’m asking is how and what part of the code do i need to change so it’ll still work even though it’s on a different layer!

Thanks!

This is the code here

> onClipEvent (enterFrame) {  
> with (\_root.player) {

// Controls Player Speed  
mySpeed = 3;

// Controls how far the Player bounces off the wall after impact  
myBounce = 3;

// keyboard controls  
if (Key.isDown(Key.DOWN)) {  
\_y += mySpeed;  
}  
if (Key.isDown(Key.UP)) {  
\_y -= mySpeed;  
}  
if (Key.isDown(Key.LEFT)) {  
\_x -= mySpeed;  
}  
if (Key.isDown(Key.RIGHT)) {  
\_x += mySpeed;  
}

// detect if edges of the player is colliding with the Maze Walls  
if (walls.hitTest(getBounds(\_root).xMax, \_y, true)) {  
\_x -= myBounce;  
}  
if (walls.hitTest(getBounds(\_root).xMin, \_y, true)) {  
\_x += myBounce;  
}  
if (walls.hitTest(\_x, getBounds(\_root).yMax, true)) {  
\_y -= myBounce;  
}  
if (walls.hitTest(\_x, getBounds(\_root).yMin, true)) {  
\_y += myBounce;  
}

// detect if Maze is finished  
if (\_root.end.hitTest(\_x, getBounds(\_root).yMax, true)) {  
\_root.gotoAndStop(3);  
}  
}  
}
