Solved

moving scripts from object to the main time line

Posted on 2004-10-28
163 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
Question by:DJLUCKYB
    2 Comments
     
    LVL 11

    Expert Comment

    by:muso120999
    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 11

    Accepted Solution

    by:
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT Security CISA, CISSP & CISM Certification

    Master the advanced techniques required to protect network resources from external threats with the IT Cyber Security bundle. Built around industry best-practice guidelines, the IT Cyber Security bundle consists of three in-depth courses.

    This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
    I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
    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 select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

    933 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now