# AS motion tween question?

**URL:** <https://forum.kirupa.com/t/as-motion-tween-question/33950>\
**Category:** Uncategorized\
**Created:** [October 25, 2003, 8:13pm UTC](https://forum.kirupa.com/t/as-motion-tween-question/33950 "2003-10-25T20:13:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Inflicted](https://avatars.discourse-cdn.com/v4/letter/i/82dd89/32.png) [@Inflicted](https://forum.kirupa.com/u/Inflicted)\
**Post date:** [October 25, 2003, 8:13pm UTC](https://forum.kirupa.com/t/as-motion-tween-question/33950/1 "2003-10-25T20:13:43Z")

</div>

I got this code from another thread, and changed it into a button event handler.  
It 's a motion tween via AS.  
Is it possible to have a second button change  
it back to it’s original shape?

```auto
btn_1.onRelease = function() {
    var hDiff = Math.round(25-this._height);
    var wDiff = Math.round(500-this._width);
    this._width += wDiff/1;
    this._height += hDiff/1;
};

```

Could anyone help me with this?

thanks,

regards

---

<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:** [October 25, 2003, 10:27pm UTC](https://forum.kirupa.com/t/as-motion-tween-question/33950/2 "2003-10-25T22:27:40Z")

</div>

I think you just need to copy the button handler you have and replace 25 and 500 with the original height and width of your clip.

---

<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:** [October 26, 2003, 6:10am UTC](https://forum.kirupa.com/t/as-motion-tween-question/33950/3 "2003-10-26T06:10:20Z")

</div>

That code does not create any motion :-\

---

<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:** [October 26, 2003, 12:40pm UTC](https://forum.kirupa.com/t/as-motion-tween-question/33950/4 "2003-10-26T12:40:43Z")

</div>

No motion???

Watch this!

www.inflicted.nl/as\_tween.fla.zip

regards

---

<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:** [October 26, 2003, 12:44pm UTC](https://forum.kirupa.com/t/as-motion-tween-question/33950/5 "2003-10-26T12:44:18Z")

</div>

404 Not Found :-  
\*Now it works.

But think: how can that possibly create motion if that code is only executed once ? To have actionscripted motion, you need a repeating code, such as in onEnterFrame handler or in a function which you call using setInterval for example. That code will only change the dimensions of that movieclip once, but there will not be any motion.

---

<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:** [October 26, 2003, 12:46pm UTC](https://forum.kirupa.com/t/as-motion-tween-question/33950/6 "2003-10-26T12:46:15Z")

</div>

That uses onEnterFrame, not onRelease 😉

---

<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:** [October 26, 2003, 12:57pm UTC](https://forum.kirupa.com/t/as-motion-tween-question/33950/7 "2003-10-26T12:57:22Z")

</div>

No, I changed it, cause I wanted it on a button…  
But it does move, right?

regards

---

<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:** [October 26, 2003, 1:20pm UTC](https://forum.kirupa.com/t/as-motion-tween-question/33950/8 "2003-10-26T13:20:21Z")

</div>

Like Voetsjoeba says, you need to do the motion in a function that gets executed over more than one frame.

That’s what it does now. onEnterFrame gets executed once every frame. onRelease only gets executed once when you press the button. You can change the size in onRelease but it won’t be a smooth change.

I’d suggest that you make 2 functions: expand and contract. When you hit button 1, you set the onEnterFrame event to execute the expand function. And when you hit button 2, you set onEnterFrame to execute the contract function.

---

<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:** [October 26, 2003, 3:15pm UTC](https://forum.kirupa.com/t/as-motion-tween-question/33950/9 "2003-10-26T15:15:55Z")

</div>

There’s probably a better way of doing what I want. But I came across this code while searching.  
I wanted a button that expanded, and once another btn  
was pressed contracted.  
Still got so much to learn…

thanks

regards
