# I think I need to optimise

**URL:** <https://forum.kirupa.com/t/i-think-i-need-to-optimise/176647>\
**Category:** flash\
**Created:** [January 25, 2006, 7:58pm UTC](https://forum.kirupa.com/t/i-think-i-need-to-optimise/176647 "2006-01-25T19:58:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonbid](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jonbid](https://forum.kirupa.com/u/jonbid)\
**Post date:** [January 25, 2006, 7:58pm UTC](https://forum.kirupa.com/t/i-think-i-need-to-optimise/176647/1 "2006-01-25T19:58:28Z")

</div>

I have a flash movie, and I decided to learn how to use the tween classes in Flash 8. I think, however, that somewhere along the line I got carried away… and my script seems to run very slowly, even on 50 frames per second.

[http://hguk.net/~jonbid/scripted.html](http://hguk.net/%7Ejonbid/scripted.html)

I have not yet been able to figure out a way of making it run faster.

I have used functions and called them using if statements on buttons.

Anyway here is the bulk of the script, which I think is the problem, I have also attached the fla.

```auto

import mx.transitions.Tween;
import mx.transitions.easing.*;
myframes = 18;
open_portfolio = function () {
    mov_port._visible = true;
    _global.mylock = 1;
    var greyTop:Tween = new Tween(top_part, "_y", Bounce.easeOut, top_part._y, (top_part._y-100), myframes, false);
    var greyBot:Tween = new Tween(bottom_part, "_y", Bounce.easeOut, bottom_part._y, (bottom_part._y+100), myframes, false);
    greyTop.onMotionFinished = function() {
        var portAlp:Tween = new Tween(mov_port, "_alpha", Regular.easeOut, 0, 100, myframes, false);
        var greyTop:Tween = new Tween(top_part, "_x", Bounce.easeOut, top_part._x, (top_part._x-160), myframes, false);
    };
    greyBot.onMotionFinished = function() {
        var greyBot:Tween = new Tween(bottom_part, "_x", Bounce.easeOut, bottom_part._x, (bottom_part._x-160), myframes, false);
    };
};
// end of open portfolio function
open_contact = function () {
    mov_cont._visible = true;
    _global.mylock = 0;
    var greyTop:Tween = new Tween(top_part, "_y", Bounce.easeOut, top_part._y, (top_part._y-100), myframes, false);
    var greyBot:Tween = new Tween(bottom_part, "_y", Bounce.easeOut, bottom_part._y, (bottom_part._y+100), myframes, false);
    greyTop.onMotionFinished = function() {
        var contAlp:Tween = new Tween(mov_cont, "_alpha", Regular.easeOut, 0, 100, myframes, false);
        var greyTop:Tween = new Tween(top_part, "_x", Bounce.easeOut, top_part._x, (top_part._x+160), myframes, false);
    };
    greyBot.onMotionFinished = function() {
        var greyBot:Tween = new Tween(bottom_part, "_x", Bounce.easeOut, bottom_part._x, (bottom_part._x+160), myframes, false);
    };
};
// end of open contact function
close_portfolio = function () {
    var portAlp:Tween = new Tween(mov_port, "_alpha", Regular.easeOut, 100, 0, myframes, false);
    var greyTop:Tween = new Tween(top_part, "_x", Bounce.easeOut, top_part._x, (top_part._x+160), myframes, false);
    var greyBot:Tween = new Tween(bottom_part, "_x", Bounce.easeOut, bottom_part._x, (bottom_part._x+160), myframes, false);
    greyTop.onMotionFinished = function() {
        var greyTop:Tween = new Tween(top_part, "_y", Bounce.easeOut, top_part._y, (top_part._y+100), myframes, false);
        mov_cont._visible = false;
        mov_port._visible = false;
    };
    greyBot.onMotionFinished = function() {
        var greyBot:Tween = new Tween(bottom_part, "_y", Bounce.easeOut, bottom_part._y, (bottom_part._y-100), myframes, false);
    };
};
// end of close contact function
close_contact = function () {
    var contAlp:Tween = new Tween(mov_cont, "_alpha", Regular.easeOut, 100, 0, myframes, false);
    var greyTop:Tween = new Tween(top_part, "_x", Bounce.easeOut, top_part._x, (top_part._x-160), myframes, false);
    var greyBot:Tween = new Tween(bottom_part, "_x", Bounce.easeOut, bottom_part._x, (bottom_part._x-160), myframes, false);
    greyTop.onMotionFinished = function() {
        var greyTop:Tween = new Tween(top_part, "_y", Bounce.easeOut, top_part._y, (top_part._y+100), myframes, false);
        mov_cont._visible = false;
        mov_port._visible = false;
    };
    greyBot.onMotionFinished = function() {
        var greyBot:Tween = new Tween(bottom_part, "_y", Bounce.easeOut, bottom_part._y, (bottom_part._y-100), myframes, false);
    };
};
// end of close contact function
swapto_contact = function () {
    mov_cont._visible = true;
    if (_global.mylock != 0) {
        var portAlp:Tween = new Tween(mov_port, "_alpha", Regular.easeOut, 100, 0, myframes/2, false);
        var greyTop:Tween = new Tween(top_part, "_x", Bounce.easeOut, top_part._x, (top_part._x+320), myframes, false);
        var greyBot:Tween = new Tween(bottom_part, "_x", Bounce.easeOut, bottom_part._x, (bottom_part._x+320), myframes, false);
        portAlp.onMotionFinished = function() {
            var contAlp:Tween = new Tween(mov_cont, "_alpha", Regular.easeOut, 0, 100, myframes/2, false);
        };
        _global.mylock = 0;
    }
    // end of if statement
};
// end of swapto contact function
swapto_portfolio = function () {
    mov_port._visible = true;
    if (_global.mylock != 1) {
        var contAlp:Tween = new Tween(mov_cont, "_alpha", Regular.easeOut, 100, 0, myframes/2, false);
        var greyTop:Tween = new Tween(top_part, "_x", Bounce.easeOut, top_part._x, (top_part._x-320), myframes, false);
        var greyBot:Tween = new Tween(bottom_part, "_x", Bounce.easeOut, bottom_part._x, (bottom_part._x-320), myframes, false);
        contAlp.onMotionFinished = function() {
            var portAlp:Tween = new Tween(mov_port, "_alpha", Regular.easeOut, 0, 100, myframes/2, false);
        };
        _global.mylock = 1;
    }
    // end of if statement
};
// end of swapto portfolio function

```

It is rediculously long… 😟

Any ideas on how to get rid of this slow jerky animation? or just reducing this script?

Any help is huuuugely appreciated
