Move an MC with arrow keys

Code is on MC. I need help putting it in the timeline

Page 1 of 1

4 Replies - 1022 Views - Last Post: 12 September 2008 - 07:48 AM

#1 icedd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 04-March 08

Move an MC with arrow keys

Post icon  Posted 11 September 2008 - 01:19 PM

Hey I want to be able to transfer this to my time line rather then have the code on my MC it slef.

onClipEvent (enterFrame) {
		if (Key.isDown(Key.UP)) {
		this._y -=15;
		}
		
		if (Key.isDown(Key.DOWN)) {
		this._y +=15;
		}
		
		if (Key.isDown(Key.LEFT)) {
		this._x -=15;
		}
		
		if (Key.isDown(Key.RIGHT)) {
			this._x +=15;
		}
}




I'm reading my AS book that I bought and from my understanding I should be writing it like this if I want to have the same outcome but have the script in my Time line rather then my MC but it doesn't work ( move_obj ) is the instance name of my MC

move_obj.enterFrame = function () {
		if (Key.isDown(Key.UP)) {
		this._y -=15;
		}
		
		if (Key.isDown(Key.DOWN)) {
		this._y +=15;
		}
		
		if (Key.isDown(Key.LEFT)) {
		this._x -=15;
		}
		
		if (Key.isDown(Key.RIGHT)) {
			this._x +=15;
		}
}

This post has been edited by icedd: 11 September 2008 - 02:31 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Move an MC with arrow keys

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1134
  • View blog
  • Posts: 7,094
  • Joined: 07-September 06

Re: Move an MC with arrow keys

Posted 11 September 2008 - 03:11 PM

Really?

It looks like it should work out. You made sure that the instance name of the movieclip is exactly the same as the as above (move_obj)?

You may want to see if it can be done like so:
(With the same code, just making a movieclip on the spot that is easy to see and know if it is working)
function init(){
  var obj:MovieClip = _root.createEmptyMovieClip("move_obj", 100);
  createFill(obj, 100, 100, 2, 0x9999ff, "Gradient", [0x000000, 0x00ff00]);
  obj.onEnterFrame = function(){
	trace("Frame entered");
	//place movement code here to make it able to move, at least it should...
  } 
}

function createFill(obj:MovieClip, w, h, border, borderColor, bgStyle, bgColors){
	obj.lineStyle(border, borderColor, 100);
	if(bgStyle == "Gradient"){
		alphas = [100, 100];
		ratios = [0, h*1.5];
		matrix = {matrixType:"box", x:0, y:0, w:430, h:150, r:Math.PI/2};
		obj.beginGradientFill("linear", bgColors, alphas, ratios, matrix);
	}
	else if(bgStyle == "Solid"){
		obj.beginFill(bgColors[0], 100);
	}
	obj.lineTo(w, 0);
	obj.lineTo(w, h);
	obj.lineTo(0, h);
	obj.lineTo(0, 0);
	if(bgStyle != "None"){
		obj.endFill();
	}
}

init();


Hope that helps.
Was This Post Helpful? 0
  • +
  • -

#3 icedd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 04-March 08

Re: Move an MC with arrow keys

Posted 11 September 2008 - 04:41 PM

Hey, I appreciate the help! Although sadly that's still to advanced for me yet. But I did find out what I was doing wrong.

I had
move_obj.EnterFrame = function() {


instead of
move_obj.onEnterFrame = function() {


Notice the "on"EnterFrame

Stupid syntax

Thanks for showing your concern though :)

ICEDD
Was This Post Helpful? 0
  • +
  • -

#4 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1134
  • View blog
  • Posts: 7,094
  • Joined: 07-September 06

Re: Move an MC with arrow keys

Posted 11 September 2008 - 04:42 PM

No problem, I have posted a few flash tutorials if you want to get some help on the basics, just check the tutorials section.
Was This Post Helpful? 0
  • +
  • -

#5 icedd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 04-March 08

Re: Move an MC with arrow keys

Posted 12 September 2008 - 07:48 AM

Thank you. Will do :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1