Flash Math Question

Ever figure out how to do something and have a nagging feeling that you might be doing it the hard way?

I need to determine the pixel location that is 50 pixels to the left of a mc “hslider” on load. I want to be able to reuse the code, or I’d just look and see what it is.

Anyway, I figured out how to do it, but I’m just wondering if there’s a better way.

while (i < Stage.width) {
if(findIt==50) {
foundIt=i;
}
i++
}

I don’t understand. I mean you have that line:

``````findIt=roundedLoadPosition-i;
``````

where you know finIt (50) and roundedLoadPosition (whatever), so why do you do all that? Does the position of your clip change or what?

pom :asian:

Yes, I’m trying to create reusable code. I need to be able to place this movie in any other movie and not need to re-calculate its coordinates everytime. This code works fine for that. Really my root question is this - regardless of that code.

I needed to figure out:

50 = (myMovie._x - n)

I need to place the movie any place and be able to have the ActionScript calculate the value of “n”. Like I said. The code I have works, I’m just wondering if there’s an easier way to find “n” than what I did. I know there’s a lot of Flash math that I’m not familiar with and was wondering if something existed for this.

:x Well… 50 = (myMovie._x - n) is equivalent to

``````n=myMovie._x - 50;
``````

isn’t it? And if you want to reuse that code, you can make it a prototype, even though it doesn’t do much (check the AS trick section for examples).

I have the awful feeling that I don’t understand what you’re trying to do though

pom :asian:

Well, that’s why I asked. I knew there was something I was overlooking, and I was making it more complicated than it needed to be. Sometimes I get so caught up in solving the ActionScript that the obvious gets blurry.

Thanks.

I may be missing something, Kenny, please ignore me if that’s so. But couldn’t the following code in the slider movie clip do the trick? The code could be reused no matter which movie/movieclip you use it in.

_root.distanceVariable = this._x - 50;

No, you’re right on. I think that’s what ilyaslamasse was so tactfully saying, too. Thanks.