(Help!) moving MC script

2 posts Page 1 of 1
Contributors
User avatar
backo
Just Registered
Just Registered
Posts: 6
Joined: Thu Dec 02, 2010 9:43 pm

(Help!) moving MC script
backo
well, i only have one simple problemi cant figure a script to move one movieclip to another movieclip by the push of a button, lets say... space.

heres a example of the script i cant make work
Code: Select all
onClipEvent(EnterFrame){
     if(Key.isDown(Key.SPACE)){
        this._x = clip._x
        this._y = clip._y
     }
}
but it does not work, if anyone knows what im doing wrong, please help me.

thanks :)
User avatar
Twiffler
Member
Member
Posts: 46
Joined: Wed Sep 22, 2010 10:50 pm

Re: (Help!) moving MC script
Twiffler
The code you are using is almost right. The problem is your not telling were the movie clip is in the hierarchy. To fix it you need to add _root. to go to the top of the hierarchy then put the instance name of the movie clip next.
this is the modified code
Code: Select all
onClipEvent (enterFrame) {
	if (Key.isDown(Key.SPACE)) {
		this._x = _root.MovieClip2._x;
		this._y = _root.MovieClip2._y;
	}
}
this code is on the movie clip that is going to be moved. One more thing I usually prefer to put the code on one frame to keep it localized. Here is how that is done
Code: Select all
onEnterFrame = function () {
	if (Key.isDown(Key.SPACE)) {
		_root.MovieClip1._x = _root.MovieClip2._x;
		_root.MovieClip1._y = _root.MovieClip2._y;
	}
};


hoped this helped cooll; !
2 posts Page 1 of 1
Return to “Tutorials”