Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 12-17-2010, 05:07 AM   #1
Registered User
Join Date: Dec 2010
Posts: 2
Default [AS2] Moving Platforms Problem

I have been having this problem for a while. Basically, I am trying to get the instance "Player" to move with the moving platform while on top of it.

I got the script to work, but it only works if the platform is not in a movie clip. The script is put on the platform movieclip.

onClipEvent (load) {
distx = 0;
disty = 0;
pos = 0;
onClipEvent (enterFrame) {
pos={x:_x, y:_y};
if (_root.Player.hitTest(this)) {
_root.Player._x = pos.x+distx;
_root.Player._y = pos.y-disty;
if (Key.isDown(Key.LEFT)) {
distx -= 5;
if (Key.isDown(Key.RIGHT)) {
distx += 5;
} else {
distx = _root.Player._x-pos.x;
disty = _root.Player._y-pos.y;

However, I need the platform to be inside a movieclip, but I can't seem to make the script work properly. Is it possible to convert the variable pos to global coordinates?

One last thing, the platform does not have a certain speed or direction. It will be moving around in an animation. It does not have an instance name because I am going to have multiple.
Gfizzle is offline   Reply With Quote
Old 12-17-2010, 11:41 AM   #2
Registered User
Join Date: Dec 2010
Posts: 2


ActionScript Code:
// This IS NOT actual working code. globalX = localX + parentX; // And globalY = localY + parenty;

In your case, this would be:

ActionScript Code:
// This IS actual working code globalpos={x:_x+_parent._x, y:_y+_parent._y};

Please not that this only works for movieclips inside another movieclip, with the latter being on the main timeline. For a movieclip in a movieclip in a movieclip, use
ActionScript Code:
globalX = localX + _parent._x + _parent._parent._x
I hope you see how this works, ask me if you don't.

Last edited by Flashtoo; 12-17-2010 at 03:03 PM. Reason: Edited code to use "pos.x" and "pos.y"
Flashtoo is offline   Reply With Quote
Old 12-17-2010, 09:58 PM   #3
Registered User
Join Date: Dec 2010
Posts: 2

It worked. Thanks.
Gfizzle is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 04:44 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.