# Need some help

**URL:** <https://forum.kirupa.com/t/need-some-help/13233>\
**Category:** Uncategorized\
**Created:** [February 10, 2003, 5:02pm UTC](https://forum.kirupa.com/t/need-some-help/13233 "2003-02-10T17:02:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Theta](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@Theta](https://forum.kirupa.com/u/Theta)\
**Post date:** [February 10, 2003, 5:02pm UTC](https://forum.kirupa.com/t/need-some-help/13233/1 "2003-02-10T17:02:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 5:17pm UTC](https://forum.kirupa.com/t/need-some-help/13233/2 "2003-02-10T17:17:01Z")

</div>

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

as easy as 1 2 3 =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 5:37pm UTC](https://forum.kirupa.com/t/need-some-help/13233/3 "2003-02-10T17:37:21Z")

</div>

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). ☹

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

Theta

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 5:53pm UTC](https://forum.kirupa.com/t/need-some-help/13233/4 "2003-02-10T17:53:57Z")

</div>

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 ?? 😉

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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 6:06pm UTC](https://forum.kirupa.com/t/need-some-help/13233/5 "2003-02-10T18:06:52Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 6:26pm UTC](https://forum.kirupa.com/t/need-some-help/13233/6 "2003-02-10T18:26:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 6:58pm UTC](https://forum.kirupa.com/t/need-some-help/13233/7 "2003-02-10T18:58:42Z")

</div>

i’d use this

```auto
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

```auto
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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 7:19pm UTC](https://forum.kirupa.com/t/need-some-help/13233/8 "2003-02-10T19:19:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 7:24pm UTC](https://forum.kirupa.com/t/need-some-help/13233/9 "2003-02-10T19:24:27Z")

</div>

no problem **Theta** =)
