18 Replies Latest reply on Jun 16, 2012 7:22 AM by DallasBrown

    on mouseUp go to....

    DallasBrown

      Hello,

       

      I'm looking for some help with a mouseUp function on a slider thumb.

       

      The thumb slides horizontally from horizontal position 300 to horizontal position 600. As it slides, a set of words appears to the right of the slider track: blues, classical, folk, jazz, reggae, RnB, rock. These are not bitmaps but instead are text cast members in different font styles.

       

      The intention is that stopping at the point when any one of those words appear and releasing the mouse should take the playhead to a marker bearing the same name: blues, classical, etc.

       

      Here is the script I'm using (called "stagesSlider) to make the slider work. If anyone can tell me what to add to it to make the playhead jump to each different marker at the appropriate moment, I would be grateful:

       

      -- gStages holds the percent (0 - 100) value of where the slider is currently at.

      global gStages

      global StagesList

      global StagesNumVal

      global StagesCreate

      global SelectedStages

       

      -- When the mouse enters the sprite..

      on mouseEnter

        -- Go to the "stageChoice" marker

        go to "stageChoice"

       

        -- yval is the location of the sprites on the "Y" axis

        yval = 55

        -- StagesNumVal is the "base" number for the new sprites that are created.

        StagesNumVal = 90

        -- StagesList is the "array" or list that holds all the names for the text sprites.

        StagesList = ["skinBlues","skinClassical","skinFolk","skinJazz","skinR&B","skinReggae","skinRock"]

        -- The repeat loop for setting all the sprites.

        repeat with indexcount = 1 to StagesList.count

          -- Create the sprite by setting its channel.

          channel(StagesNumVal+indexcount).makeScriptedSprite(member(StagesList[indexcount]), point(700,yval))

          -- Set the sprite's transparency (or blend) to 0 (aka totally transparent)

          sprite(StagesNumVal+indexcount).blend = 0

          sprite(StagesNumVal+StagesCreate).blend = 100

         

          -- Update the stage so that things keep moving while the loop is executing

          updateStage

        end repeat

       

      end

       

      -- When the mouse is pressed..

      on mouseDown me

        -- step calcualtes each menu item's place on the slider.

        step = 100.0/StagesList.count

        step = step + (step/StagesList.count)

       

        -- While the mouse is held down do...

        repeat while the stillDown

          -- The "H" position of the mouse

          posH = the mouseH

         

          -- The "V" position of the sprite

          posV = sprite(the clickOn).locV

         

          -- If the "H" position of the sprite is less than 300 then set it back to 300

          -- If the "H" position of the sprite is greater than 600 then set it back to 600

          if sprite(the clickOn).locH < 300 then

            posH = 300

          else if sprite(the clickOn).locH > 600 then

            posH = 600

          end if

         

          -- If the "H" position of the mouse is greater than or equal to 300 and

          -- is less than or equal to 600 then..

          if the mouseH >= 300 and the mouseH <= 600 then

            -- Set the sprite location on the "X" (or "H" if you will) axis.

            sprite(the clickOn).loc = point(posH, posV)

           

            -- Calculate the percentage of the slider position and put it in the

            -- global variable "gStages".

            gStages = ((sprite(the clickOn).locH-300.0)/300.0)*100.0

          end if

         

          -- ***** Menu item animation *****

          menupos = integer(gStages/step)+1

          StagesCreate = menupos

          SelectedStages = menupos

         

          -- sprite 9 is the channel where the list of names appears (blues, classical, etc)

          sprite(9).visible = false

          if menupos = 1 then

            sprite(StagesNumVal+menupos).blend = 100

            sprite(StagesNumVal+menupos+1).blend = 0

          else if menupos = StagesList.count then

            sprite(StagesNumVal+menupos-1).blend = 0

            sprite(StagesNumVal+menupos).blend = 100

            sprite(StagesNumVal+menupos+1).blend = 0

          else

            sprite(StagesNumVal+menupos-1).blend = 0

            sprite(StagesNumVal+menupos).blend = 100

            sprite(StagesNumVal+menupos+1).blend = 0

          end if

         

          -- Update the stage so everything on the stage keeps going.

          updateStage

        end repeat

      end

       

       

      Any help would be much appreciated.

       

      Dallas

        • 1. Re: on mouseUp go to....
          James Newton, ACP Level 3

          Here's a demo movie that does something similar to what you are asking for:

           

          go movie "http://nonlinear.openspark.com/tips/dragging/MusicSlider.dir"

           

          Does this help?

          • 2. Re: on mouseUp go to....
            DallasBrown Level 1

            Thank you for the quick reply. I suppose one could say that's the first step in the process that I'm after and it's the step I already have: a slider that shows changes a list of words when it's being moved. What I'm after is the next step in the process, which is on mouseUp the playhead jumps to a new marker (where more things are set to happen). Perhaps what you sent me actually does just that, but all I see is a slider that moves left/right with a set of words that appear beside the slider track.

            • 3. Re: on mouseUp go to....
              James Newton, ACP Level 3

              Perhaps you could look a little deeper. Perhaps you could look at the on DoSomethingInterestingWith(aString) handler. Do you think that might be a good place for a go marker("Whatever") statement?

              • 4. Re: on mouseUp go to....
                DallasBrown Level 1

                Please accept my apologies. I always sat at the back of the classroom with the other shin-kicking knucklejabbers and was largely considered by my teachers as being a sub-idiot (not smart enough to be an idiot).

                 

                When I use Firebug to look into the details, here is what I find:

                 

                if (window.addEventListener) {

                var callback_func = function(evt) {

                if ('undefined' != typeof evt.target && "A" == evt.target.nodeName) {

                var url = evt.target.href;

                EBCallBackMessageReceived99a38583_7fc0_4bf0_8eea_b7b26815d620(url);

                }

                return true;

                };

                var result = window.addEventListener('click', callback_func, true);

                var result = window.addEventListener('contextmenu', callback_func, true);

                } else if (document.attachEvent) {

                var callback_func = function () {

                if ('undefined' != typeof event.srcElement &&'A' == event.srcElement.tagName) {

                var url = event.srcElement.href;

                EBCallBackMessageReceived99a38583_7fc0_4bf0_8eea_b7b26815d620(url);

                }

                return true;

                };

                var result = document.attachEvent('onclick', callback_func);

                var result = document.attachEvent('oncontextmenu', callback_func);

                }

                </script>

                <script type="text/javascript">

                if (window.addEventListener) {

                var callback_func = function(evt) {

                if ('undefined' != typeof evt.target && "A" == evt.target.nodeName) {

                var url = evt.target.href;

                EBCallBackMessageReceived38049443_ce20_4c69_a62d_70c81292cf11(url);

                }

                return true;

                };

                var result = window.addEventListener('click', callback_func, true);

                var result = window.addEventListener('contextmenu', callback_func, true);

                } else if (document.attachEvent) {

                var callback_func = function () {

                if ('undefined' != typeof event.srcElement &&'A' == event.srcElement.tagName) {

                var url = event.srcElement.href;

                EBCallBackMessageReceived38049443_ce20_4c69_a62d_70c81292cf11(url);

                }

                return true;

                };

                var result = document.attachEvent('onclick', callback_func);

                var result = document.attachEvent('oncontextmenu', callback_func);

                }

                </script>

                <script type="text/javascript">

                if (window.addEventListener) {

                var callback_func = function(evt) {

                if ('undefined' != typeof evt.target && "A" == evt.target.nodeName) {

                var url = evt.target.href;

                EBCallBackMessageReceived552fa707_61dd_4786_9750_785e1037ae85(url);

                }

                return true;

                };

                var result = window.addEventListener('click', callback_func, true);

                var result = window.addEventListener('contextmenu', callback_func, true);

                } else if (document.attachEvent) {

                var callback_func = function () {

                if ('undefined' != typeof event.srcElement &&'A' == event.srcElement.tagName) {

                var url = event.srcElement.href;

                EBCallBackMessageReceived552fa707_61dd_4786_9750_785e1037ae85(url);

                }

                return true;

                };

                var result = document.attachEvent('onclick', callback_func);

                var result = document.attachEvent('oncontextmenu', callback_func);

                }

                 

                Alas, I don't see the string you're referring to. Perhaps it's nearby but, me being one of the thicks, I don't know how to find it. Is there perhaps something else I should be doing to give me access to the code to which you refer? I do appreciate your help and your patience.

                • 5. Re: on mouseUp go to....
                  James Newton, ACP Level 3

                  Sorry for the confusion. In the Message window of Director, execute the following command:

                   

                  go movie "http://nonlinear.openspark.com/tips/dragging/MusicSlider.dir"

                   

                  Director will download and open the movie. You will now be able to look at all the code inside it. You will find a Movie Script in cast slot 14. The code you are looking for is in there.

                  • 6. Re: on mouseUp go to....
                    DallasBrown Level 1

                    I'm entirely confident that the code is very close to what I'm looking for. My - somewhat unusual - problem is that the computer I use for creative work is not connected to the internet: it's my way of keeping it virus-free. And I can't even temporarily hook it up because I'm using a wifi network and it doesn't have wifi capability. So.......is there any way to send me the movie or just the code? I do apologize for being a little more bothersome than we're all used to in the online, connected, wireless age.

                    • 7. Re: on mouseUp go to....
                      James Newton, ACP Level 3

                      Can you download the file from http://nonlinear.openspark.com/tips/dragging/MusicSlider.zip to a computer that is linked to the Internet, then use a USB key to copy it across to your development computer?

                      • 8. Re: on mouseUp go to....
                        DallasBrown Level 1

                        outstanding! downloaded, copied, pasted, and.....well, obviously needs a bit of tweaking to get it to work inside my project. so, here's the first question:

                         

                        -- Create a list of all the text members to use

                        pSteps = vendMember - vStartMember +1

                        pMusicMemberList = [ ]

                         

                        what exactly do i put into the square brackets? i've tried using the names of the cast members, but that doesn't work, so then i removed all of their names and tried simply putting the cast member numbers in, but that doesn't work either. the names of my cast members are skinBlues, skinClassical, etc.

                        • 9. Re: on mouseUp go to....
                          James Newton, ACP Level 3

                          You don't put anything into the square brackets. You use the right member number for vStartMember and vEndMember, and pMusicMemberList will be automatically populated with those members and all the members in between.

                           

                          You just change the data in the HARD-CODED section to match the way your Score and Casts are arranged. The repeat loop deals with all the rest.

                           

                            -- <HARD-CODED>

                            pMusicSprite = sprite(1)

                            vStartMember = 2

                            vEndMember   = 8

                            -- </HARD-CODED>

                           

                            -- Create a list of all the text members to use

                            pSteps = vEndMember - vStartMember + 1

                            pMusicMemberList = []

                           

                            repeat with ii = vStartMember to vEndMember

                              vMember = member(ii)

                              vText   = vMember.text

                             

                              pMusicMemberList.append(vMember)

                            end repeat

                          • 10. Re: on mouseUp go to....
                            DallasBrown Level 1

                            hmmm, i tried that and when i run the movie and try to drag the thumb, what i get is a dialog box that reads:

                             

                            Script error: Index out of range

                            vMember = pMusicMemberList[pIndex]

                             

                            this occurs both when i change the vStart and vEnd numbers to match my members (which don't have names at this point) and also when i put my nameless members into positions 2 through 8 in the cast to match your script. i haven't made any other changes to the script or the cast.

                             

                            it also occurs when i put change the script to match my pMusicSprite to sprite 6 (the channel it normally sits on) and when I don't change the script and put the sprite into channel 1).

                             

                            worth noting: your movie works fine on my computer (drag the thumb left/right and the words to the left of the slider change as expected).

                            • 11. Re: on mouseUp go to....
                              DallasBrown Level 1

                              my apologies if i've worn out your patience. it wasn't my intention to do so.

                               

                              anyway, i think i've figured out most of it as i've managed to get myself to the point where i'm ready to code the DoSomethingInterestingWith(aString) part, so here is what I hope should be my last question:

                               

                              i believe i need to write a series of if/then/else statements to make this work. since there is a set of seven members in the array, i think i need something like this:

                               

                              on mouseUp if

                              pMusicSprite = member(2) then

                              go to "Blues"

                              else

                              if pMusicSprite = member(3) then

                              go to "Classical"

                              etc.

                               

                              however, i can't get this to work, no matter what combination of instructions i try, which leads me to believe i don't have a full enough understanding of scripting to do this properly. if you could just let me know how to write the first few lines of this properly, i should be able to fill in the rest.

                               

                              again, thank you for you time and patience.

                              • 12. Re: on mouseUp go to....
                                James Newton, ACP Level 3

                                How about simply:

                                • Creating a marker with the same name as the text in the text members
                                • Adding a line to the DoSomethingInterestingWith() handler

                                 

                                on DoSomethingInterestingWith(aString)

                                  put aString -- or something a bit more inspirational

                                  go marker(aString)

                                end DoSomethingInterestingWith

                                 

                                 

                                I've updated the online files:

                                 

                                go movie "http://nonlinear.openspark.com/tips/dragging/MusicSlider.dir"

                                http://nonlinear.openspark.com/tips/dragging/MusicSlider.zip

                                • 13. Re: on mouseUp go to....
                                  Dean Utian Adobe Community Professional

                                  Was just browsing this thread and thought I'd add something that's on a tagent to this discussion since I saw
                                  go marker(aString)

                                   

                                  I've noticed a quirk when using 'marker'. It works fine when jumping between markers within a single movie but does not work when jumping to another movie.


                                  For example:

                                    go marker "scene2"
                                  works fine but

                                    go marker "scene2" of movie "movie2"

                                  does not work. Director will simply jump to the first frame of movie2. Leaving out 'marker' will work 100%.

                                  • 14. Re: on mouseUp go to....
                                    DallasBrown Level 1

                                    thank you for the heads-up on that. will keep it in mind as it's the sort of thing that saves hours of frustration until the "ah-hah, now i get it" moment finally arrives.

                                    • 15. Re: on mouseUp go to....
                                      DallasBrown Level 1

                                      hi dean,

                                       

                                      didn't want you to think i'm an ingrate who profits from your helping hand without saying thank you. i really do appreciate your advice and the helpful scripts. and for the past two weeks i've been bashing my head against the wall trying to get this thing to work but to no avail, despite being probably 98% of the way there.

                                       

                                      as a standalone, your script works fine, yet when i bring it into my project, it almost works and when i build my project around your script, it almost works, but in neither case fully 100%. i'm in a cul-de-sac, don't really know what to do next and would welcome any suggestions from anybody about what the solution might be. i suspect the problem is just some tiny part of the programming but for the life of me i can't see it. i can't really describe the problem clearly here because i believe it's the sort of thing that needs to be seen to be understood.

                                      • 16. Re: on mouseUp go to....
                                        James Newton, ACP Level 3

                                        I'm not Dean : )

                                         

                                        Accurately describing a problem is an excellent way to start solving it.

                                         

                                        Reducing a problem movie to its bare bones, so that you have the absolute minimum of code and assets to reproduce the problem is a good way to identify the cause of the problem.

                                         

                                        Your latest message doesn't even give any indication as to what the problem your are seeing is.

                                         

                                        Can you:

                                        1) Create a COPY of your project, and save it as Barebones1.dir

                                        2) Remove everything that you are sure has nothing to do with the problem. Save the movie as Barebones2.dir

                                        3) Remove more stuff that has nothing to do with the problem. Save the movie as Barebones1.dir

                                        4) Repeat steps 2 and 3 until the problem disappears. When it disappears, back-up to the previously saved version, where it is still visible, and remove something else instead that doesn't make the problem disappear.

                                        5) When you get here, your project should be exceptionally simple. It should contain just enough in the Score and the Cast windows, and just enough lines of code in the scripts, to reproduce the problem. Removing anything else from your project change you make should make the problem disappear.

                                         

                                        Now you should be able either to solve the problem for yourself, or to describe it with sufficient detail for someone else to be able to solve it, or to have firm evidence that it is a bug in the Director engine itself.

                                         

                                        Is this helpful?

                                        • 17. Re: on mouseUp go to....
                                          Dean Utian Adobe Community Professional

                                          @ DallasBrown


                                          As James (OpenSpark) hinted, you mixed us up. He had given the main help in this thread so deserved more thanks than me:)


                                          I fully agree with the last post. Often, I have a problem and start writing it out with the intention to try ask someone for advice. The process of describing the problem often gives me an insight to a solution. That's because you develop a better understanding of what's happening.


                                          When asking for help on here, try give as much info as possible to what's happening in your file. And as James mentioned, try get the movie to a much simpler form, to its bare bones. If say you have a movie with video, sound and a button that is unrelated to the other elements but is causing a problem, remove the video and sound and see if the problem still occurs. Debugging is often a process of elimination. If you can eliminate as much as possible from your movie, it will be much easier to locate the cause of the problem and thereby find a solution for it.


                                          Dean

                                          • 18. Re: on mouseUp go to....
                                            DallasBrown Level 1

                                            my apologies to both you and james for a) mixing you up and b) posting something rather vague. re-reading it now, i can see it was more of a generalized cry of exasperation rather than a reasoned request for help.

                                             

                                            i have been doing more or less what both of you are suggesting about remove/test/replace/test, although perhaps not in quite as efficient a manner. i'll try it more methodically as per your suggestion and see how well that works.

                                             

                                            in the meantime, here is a description of the problem as it stands now: when i bring your script into my project and when the Music Style Selector is applied to its intended sprite but the Simple Slider behaviour is not applied to its sprite, the playhead stops as it should at a specific marker with a goToTheFrame command. But when the Simple Slider behaviour is then applied to its intended sprite, the playhead skips past that first marker and two others, each with a goToTheFrame behaviour and stops at a fourth marker which, interestingly, does not have a goToTheFrame command but instead a fairly elaborate behaviour script in the script channel. the program shouldn't do this as the playhead should instead stop at that first marker. so my assumption is there's some code in the Simple Slider that's unintentionally causing this skip, but i can't see what line of code would cause it (unless it's the Tidy Up instruction, perhaps?). what's more, when i try to remove bits and pieces of the code to see how that affects performance, i start getting dialogue boxes that tell me something's missing and, of course, then things really aren't working as expected.