11 Replies Latest reply on Sep 25, 2006 9:57 PM by kglad

    script conflict question

    calmchess333 Level 1
      I have two scripts that don't work on the same page but if I seperate them onto two seperate pages there isn't a problem.
      is there some sort of conflict issues with flash that i need to be aware of.......also these scripts only work if I press cntrl-enter....if i press f-12 to create an html file the scripts don't run in the html.....even if its on the webserver(smiles).

      so could you please point me to a website that explains how to keep conflicts from happening when writing actionscripts and answer the above concearns?
        • 1. Re: script conflict question
          kglad Adobe Community Professional & MVP
          i doubt anyone will be able to solve your problem without some specifics about the problem.
          • 2. Re: script conflict question
            calmchess333 Level 1
            well here are the specifics..........example#1 is a timer script which works similar to a stop watch ......example#2 is a timer which counts down from 5 minutes and then performs an action.......now why won't these two scripts work in diffrent layers when on the same flash page but will work when on seperate flash pages? Also why do thes scripts work when i press
            cntl-enter to compile but won't work when i compile them into a webpage by pressing f-12?

            example#1
            //initial variables
            var timing:Boolean = false;
            var paused:Boolean = false;
            var remaining:Number;
            var elapsedTime:Number;
            var elapsedHours: Number;
            var elapsedM:Number;
            var elapsedS:Number;
            var elapsedH:Number;
            var startTime:Number;
            var remaining:Number;
            var hours:String;
            var minutes:String;
            var seconds:String;
            var hundredths:String;
            //start onload
            _root.onLoad.test = function() {
            if(!_root.timing) {
            if (_root.paused) {
            _root.startTime = getTimer() - _root.elapsedTime;
            } else {
            _root.startTime = getTimer();
            }
            //start timer
            _root.paused = false;
            _root.timing = true;
            }
            }
            //start button
            _root.start_btn.onPress = function() {
            if(!_root.timing) {
            if (_root.paused) {
            _root.startTime = getTimer() - _root.elapsedTime;
            } else {
            _root.startTime = getTimer();
            }
            //start timer
            _root.paused = false;
            _root.timing = true;
            }
            }
            //stop
            _root.stop_btn.onPress = function() {
            //only stop if the timer is actually going
            if(_root.timing) {
            _root.timing = false;
            _root.paused = true;
            }
            }

            // timer function
            _root.onEnterFrame = function() {
            if (timing) {
            //calculate values
            elapsedTime = getTimer()-startTime;
            //hours
            elapsedHours = Math.floor(elapsedTime/3600000);
            remaining = elapsedTime-(elapsedHours*3600000);
            //minutes
            elapsedM = Math.floor(remaining/60000);
            remaining = remaining-(elapsedM*60000);
            //seconds
            elapsedS = Math.floor(remaining/1000);
            remaining = remaining-(elapsedS*1000);
            //hundredths
            elapsedH = Math.floor(remaining/10);
            //output to text box
            //add a 0 on the front of the numbers
            //if the number is less than 10
            if (elapsedHours<10) {
            hours = "0"+elapsedHours.toString();
            } else {
            hours = elapsedHours.toString();
            }
            if (elapsedM<10) {
            minutes = "0"+elapsedM.toString();
            } else {
            minutes = elapsedM.toString();
            }
            if (elapsedS<10) {
            seconds = "0"+elapsedS.toString();
            } else {
            seconds = elapsedS.toString();
            }
            if (elapsedH<10) {
            hundredths = "0"+elapsedH.toString();
            } else {
            hundredths = elapsedH.toString();
            }
            _root.msg.text = hours+":"+minutes+":"+seconds+":"+hundredths;
            }
            };


            example #2
            var minutes = 5; // countdown time in minutes

            onLoad = function() {
            date = new Date();
            this.targetMilli = date.getTime() + ((minutes*60)*1000);
            };

            onEnterFrame = function()
            {
            date = new Date();
            milli = this.targetMilli - date.getTime();

            if (milli <= 0)
            {
            // Code to react to timer hitting 0
            msg.text = "end of view";
            countdown.text = "1:00";

            }
            else
            {
            secs = Math.floor(milli / 1000);
            mins = Math.floor(secs / 60);

            secs = secs % 60;
            mins = mins % 60

            // countdown is a dynamic text field
            countdown.text = mins+":"+secs;

            }
            }

            • 3. Re: script conflict question
              kglad Adobe Community Professional & MVP
              i don't know why those two scripts would ever work correctly at the same time because they way each use the variable minutes is incompatible. i didn't check for other name conflicts.
              • 4. Re: script conflict question
                calmchess333 Level 1
                well i changed the minutes variable and checked for other name conflicts....but it didn't help any...those two scripts still don't run at the same time and the scripts still don't work at all if i press f-12 and create a html document.
                • 5. Re: script conflict question
                  kglad Adobe Community Professional & MVP
                  they're each using msg.text to display results.
                  • 6. Re: script conflict question
                    calmchess333 Level 1
                    sorry about that ......i didn't change that part in a previous test....although it doesn't matter at all.....I changed it and they both still don't run at the same time nor do the scripts run if I press F-12
                    • 7. Re: script conflict question
                      kglad Adobe Community Professional & MVP
                      post a link to your fla and specify the code's location.
                      • 8. Re: script conflict question
                        calmchess333 Level 1
                        sorry but i'm not letting you anywhere near my testing webserver.....the code is above does it work on your machine?
                        • 9. Re: script conflict question
                          kglad Adobe Community Professional & MVP
                          you have two onEnterFrame handlers for the same movieclip (_root). only the last one defined will work.

                          to remedy, you could create an empty movieclip for one of your handlers and use that movieclip for your onEnterFrame handler (and change your path references) or just move all the code one of the handlers to the other and remove one handler.

                          p.s. your _root.onLoad.test function never executes.
                          • 10. Re: script conflict question
                            calmchess333 Level 1
                            hey if you can rewrite the code to make it work for me i'll forever be your slave.
                            because i've done everything you thought of and it still doesn't work.
                            • 11. Re: script conflict question
                              kglad Adobe Community Professional & MVP
                              try: