Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

moving scripts from object to the main time line

Posted on 2004-10-28
2
Medium Priority
?
184 Views
Last Modified: 2010-04-03
I am trying to move away from attaching script to movie clip instanced or button and put them on the main timeline.
I have created simple flash movie, with 3 buttons left,center,right . They contro the position of a movie clip which is just a picture w 1200 h 200.
when I apply the cript to the button instances it works just fine however the script on the main timeline does not work (some but not desired effect) any idea as to what I am doing wrong
here is the original script
right button:
on (release) {
targetx = 600;
slide.gotoAndPlay("move");
}
center button:
on (release) {
targetx = 200;
slide.gotoAndPlay("move");
}
right button:
on (release) {
targetx = -200;
slide.gotoAndPlay("move");
}

main script
stop();
baseRate =1.6;
difference = _root.targetx-_root.panel._x;
rate = difference/baseRate;
_root.panel._x += rate;


////////
now I replaced the above script with one all present on the main timeline. while the script execute it does not at all move smoothly nor to the exact position it should.
I named the slide clip panel_mc
stop();
function slide(targetx:Number):Void {
      var targetx:Number = targetx;
      var baseRate:Number = 1.6;
      var difference:Number = targetx-panel_mc._x;
      var rate:Number = difference/baseRate;
      panel_mc._x += rate;
}
left_btn.onRelease = function() {
      slide(600);
};
center_btn.onRelease = function() {
      slide(200);
};
right_btn.onRelease = function() {
      slide(-200);
};

0
Comment
Question by:DJLUCKYB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 10

Expert Comment

by:muso120999
ID: 12438234
Just a quick amendment, which can be refined if you like, but this should give you a start:

stop();
function slide(targetx:Number):Void {
      panel_mc.targetx = targetx;
      panel_mc.onEnterFrame = function() {
            var baseRate:Number = 1.6;
            var difference:Number = this.targetx-panel_mc._x;
            var rate:Number = difference/baseRate;
            panel_mc._x += rate;
      };
}
left_btn.onRelease = function() {
      slide(600);
};
center_btn.onRelease = function() {
      slide(200);
};
right_btn.onRelease = function() {
      slide(-200);
};



The key is to get it to update until it's done.

muso
0
 
LVL 10

Accepted Solution

by:
muso120999 earned 1000 total points
ID: 12438276
Ok, refined it slightly - this one hits the target exactly, and then stops trying to animate further...

function slide(targetx:Number):Void {
      panel_mc.targetx = targetx;
      panel_mc.onEnterFrame = function() {
            var baseRate:Number = 1.6;
            var difference:Number = this.targetx-panel_mc._x;
            var rate:Number = difference/baseRate;
            panel_mc._x += rate;
            if (Math.abs((panel_mc._x - this.targetx))<1) {
                  panel_mc._x = this.targetx;
                  delete this.onEnterFrame;
            }
      };
}
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question