Need some help

Hi all!

I need some help with a problem I’m having:

I have a movie that consists of one frame with a button and two MC’s (objectA and container). In that frame, I have objectA scripted to move to postitionX when the button is released. What I want to do (and can’t figure out) is load an external swf into container once objectA reaches positionX. How do I do that? Any help would be appreciated. Thanx.

Theta

if (objectA._x == positionX) {
container.loadMovie (“some.swf”)
}

as easy as 1 2 3 =)

Thanx for the reply kax. That’s what I tried initially and I figured it should have worked, but it didn’t. I thought maybe it was because when the button is release, objectA is not yet at positionX, so the movie doesn’t load.

With that in mind, I tried it with onEnterFrame and onLoad, but those all had the same result and left me thinking the same thing- objectA is not at positionX when the script is executed so it doesn’t load the movie (I could be missing something here, though). :frowning:

Again, thanx for your reply, and if you have any other ideas on what’s giving me this trouble, please post 'em.

Theta

if the movement of objectA has easing …
it’s probably that objectA never reaches positionX exactly

example:

if positionX equals 420
maybe objectA._x is 419.8

just to give an idea … get the point ?? :wink:

in that case … you could solve the problem with Math.ceil or Math.floor

if positionX is greater than objectA._x you’d use something like
objectA._x += Math.ceil ((positionX - objectA._x) * .1)

if positionX is less than objectA._x you’d use
objectA._x += Math.floor ((positionX - objectA._x) * .1)

attach your fla so i can take a look :slight_smile:

i forgot …

Math.ceil rounds the number to the closest integer that is greater than or equal to the number

Math.floor rounds the number to the closest integer that is less than or equal to the number

and check objectA x position with this script. place it in the timeline

this.onEnterFrame = function () {
	trace (objectA._x)
}

Since this problem is a small part of a bigger fla I’m working with, I made a sample with the exact code I’m using to make the movement occur. I’m familiar with what you noted above about easing and the object never really reaching positionX (without extra help of course :)), and so, I don’t think that’s it. But, take a look and tell me what you think. I’m no expert with AS and I could be missing something.

Theta

i’d use this

endX = 44;
speed = 15;
button.onRelease = function() {
	objectA.onEnterFrame = function() {
		trace(objectA._x);
		if (objectA._x != endX) {
			objectA._x += Math.floor((endX-objectA._x)/speed);
		} else {
			objectA._x = endX;
			if (!loadswf) {
				container.loadMovie("some.swf");
				loadswf = true;
			}
		}
	};
};

or … the way you have the script

endX = 44;
speed = 15;
button.onRelease = function() {
	objectA.onEnterFrame = function() {
		trace(objectA._x);
		if ((Math.ceil(objectA._x)<(Math.ceil(endX-.25))) || (Math.ceil(objectA._x)>(Math.ceil(endX+.25)))) {
			objectA._x += (endX-objectA._x)/speed;
		} else {
			objectA._x = endX;
			if (!loadswf) {
				container.loadMovie("some.swf");
				loadswf = true;
			}
		}
	};
};

both work :slight_smile:

It DOES work! Thanks! You helped a ton. I appreciate it. =)

no problem Theta =)