Needa little help with basic "_x" script (x positioning)


I have contructed a movie, which consists of 6 buttons.
upon clicking a button text will appear in a box in the center of the movie clip (dif text for each button).

To demonstrate to the user which of the 6 buttons they are currently on, I want a “pointer” to slide about under the buttons.

I have constructed the following script for the pointer to move.

This script is attached to only 1 button (just want to get 1 button working at first) :

on (release) {
    if (pointer._x == -155.0) {
        pointer._x = -155.0;
    } else if (pointer._x>-155.0) {
        rateOfChange = 5;
        pointer._x -= rateOfChange;
        if (pointer._x == -155.0) {
            pointer._x = -155.0;
    } else if (pointer._x<-155.0) {
        rateOfChange = 5;
        pointer._x += rateOfChange;
        if (pointer._x == -155.0) {
            pointer._x = -155.0;

“pointer” is the instance name of my movie clip with the pointer in it.

Ok the problem is this script “kind of” works.
But It moves “5” each time the button is pressed. if you press is like 20 times it gets to where it is supposed to be! However I want it to slide accross after only 1 press!
What do I need to change to do this?

PS. I KNOW I could make it work with slight alterations using “onclip event” script attached to “pointer”, but I would like to know what I need to do to get it working like this. If possible :stuck_out_tongue: because it keeps thing simpler, easier to change and more mogical (In my mind)

So basically I don’t need to know what I need to do to make it work with on clip event. I’m such a pain in the ass eh?

Those who have read my posts before will know I like to do things My way, and hate to know why things that should work don’t. :bandit:

  • I am still using FLASH (5) FIVE, until I get a bigger screen :ninja:

Thanks for help

so you dont want to use the enterFrame event? interesting.

well you have to find another way to get your script to loop until the pointer is in the correct position. You could use a while loop set location = false and when the pointer gets to the right position set loaction = true breaking the loop. Personally Id just use the enterFrame event.


Yeah well I came to the same conclusion - I need a dif way of looping the script so came up with this :

on (release) {
    if (pointer._x == -155.0) {
        stop ();
    while (newpos<>-155.0) {
        rateOfChange = 1;
        newpos=(pointer._x -= rateOfChange);
    if (newpos == -155.0) {
        stop ();

I know the start position of the pointer is 0.

Its not exactly as you said, but it basically the same thing right?

it does go to the right point, but it doesn’t go 1 pixel at a time it just appears there :frowning:

if you were just looking for a real easy way, why not just use tweens that are “under” the buttons? I mean, that really may be the easiest way. What would I use (rhetorical)? Hmm… enterframe… I’m pretty sure.
I’ll take a look at your code.

if you were just looking for a real easy way, why not just use tweens that are “under” the buttons?

if you mean tween rather than script, I disagree. You can press the buttons in ANY order, so there is no telling where the pointer will have to move.

I would need a lot of tweens (36 in total) and a lot of stop and go frames… its much easier with script and keeps file size down. I may consider adding 1 or 2 more buttons in the future, if I want to add several more buttond we are looking at 3 figures in terms of tweens.

I just like to know why things work, and conversely why they don’t. When it seems right (like err now) it drives me insane, may seem a bit stupid I know, especially as I know the code to make it work with onclip event!
In the long run I believe it will help my overall understanding of not only actionscript but code structures of other languages also.

Admitedly sometimes you just have settle for something that works, especially if complicated. This is very basic and I don’t think I am far wrong. Some of the code posted here is way above this little bit of scripting.

right now with the code I added (shown above) its just jumping to the location all in 1 action… and I have no idea why, to me it seems like I’m telling it to move 1 pixel at a time, it has 155 pixels to travel, and it takes 1 miilisecond… hmmm

Well, I guess I did not visualize your “vision” of the button arrangement, and I would disagree on the 36 tween thing (not important! heheheh). I will agree, though, that repetitive actions can almost always warrant actionscripting (sound contradictory?). All this to say that the easy way out may not always be script, and that was the only point I was trying to make.

With that said, the reason your pointer “jumps” to that location is because your script is calculated so fast you are simply not able to say it. Therefore, when you use enterframe, the action is not executed until you view each frame. A great difference in time! enough so that you can actually see the result of the calculation as it “moves” across the frames.

I thought my code was correct… it kind of is… I didn’t realise it calculated that fast.
I guess the only way round it is onclip event then, thanks for sorting that out… well maybe I could actually… naaa had enough of cluttering up the forums :bandit:

oh regarding the 36 tween it is think about it :

say the pointer starts just off the screen _

button 1 - 1
1- 5


etc, each one will have 6 posible locations the button can get to…

but yr right, not important. I wasn’t *****in sorry if it sounded like that, I’m in a bad mood, but I feel a bit better thanks to you :stuck_out_tongue:

if you want it to loop why dont you use this?

_root.onEnterFrame = function(){
put the rest of ur code in here...

And that should work when you press the button. remember to go _root.onEnterFrame = null when the loop finishs to stop using any cpu… hehe cya :slight_smile: