10 Replies Latest reply on Oct 11, 2006 10:33 AM by andyulrika_is_back

    Returning to a Hyperlink

    andyulrika_is_back Level 1
      Hello

      Is the following possible and if so could someone please help me achieve it!

      I'm currently creating a reference CD-ROM and want the user to be able to click on a text hyperlink from a movie and jump to another movie / marker then when the other destination is displayed a text link at the bottom of the page displays - "return to (the name of the hyperlink)". Also, when the user is not using hyperlinks - the text "return to" is invisible.

      i.e. If I have a hyperlink called Volkswagon Engines then the new page displays "return to Volkswagon Engines"

      Thanks in advance

      Andy
        • 1. Re: Returning to a Hyperlink
          duckets Level 1
          You could set a pref file which contains the movie name, frameLabel, of the referring link. Eg:

          -----------------------------------------------------
          previousData = ["movie":the moviepath&the moviename, "label":the frameLabel]
          setpref("navigate_previous",string(previousData))
          -----------------------------------------------------


          Then, in your sub-movie, you can check whether the"navigate_previous" pref contains any data. If so, you display the label name in a text field, and use the data for the link:

          -----------------------------------------------------
          property previousData

          on beginsprite me
          previousData = value(getpref("navigate_previous"))
          myMem = sprite(me.spritenum).member
          if listp(previousData) then
          myMem.text = "Return to '"&previousData["label"]&"'"
          else
          myMem.text = ""
          end if
          end

          on mouseUp me
          if listp(previousData) then
          go(previousData["movie"],previousData["label"])
          end if
          end

          -----------------------------------------------------

          hope this helps!
          (untested code - provided for example only, may need tweaking!)

          - Ben

          • 2. Re: Returning to a Hyperlink
            andyulrika_is_back Level 1
            Hi Ben

            Thanks for your help, this is exactly what I want to achieve. Although I'm a little confused as to how to implement your code - being a lingo novice. What is a pref file? Is this a field member? And for the property PreviousData script - do I attach this to an invisible member on the stage.

            Any help much appreciated.

            regards

            Andy

            • 3. Re: Returning to a Hyperlink
              duckets Level 1
              Pref files are a built-in way that director provides you to save data onto the user's local computer. They're small text files which are automatically created in a 'prefs' folder (if running in a projector), or the shockwave folder (if running on the web). They're very similar to cookies, if you're familliar with how they work.

              They're ideal for saving small bits of data relating to the user's choices and preferences (hence the name).

              To implement:

              the first portion of code (the 2 lines) would need to be place somewhere so that it gets activated when the user clicks something to navigate away from the current movie.

              Eg, you could create a new behaviour, and put those lines in the 'mouseup' handler, like this:


              ----------------------------------------------------
              on mouseUp me
              previousData = ["movie":the moviepath&the moviename, "label":the frameLabel]
              setpref("navigate_previous",string(previousData))
              end
              -----------------------------------------------------

              then place that behaviour on any button which navigates away from the current movie.

              The second portion of code I pasted is a complete behaviour in itself, intended to be placed on your 'back' button (which is assumed to be a text field, because the behaviour sets the text to an appropriate phrase). So to use it, create a new behaviour, paste that code into it, and then place the behaviour on a text field which will act as your 'back' button.

              hope this helps.

              - Ben
              • 4. Re: Returning to a Hyperlink
                andyulrika_is_back Level 1

                Hi Ben

                Thanks again for your help. Still having trouble getting it to work.

                Here is what I have so far:

                I have a word inside a piece of text I wish to jump to another marker within the same movie...
                From the text inspector I added the marker name in the Hyperlink Data box after highlighting the word.
                I then dropped the following script onto the entire text member:

                on hyperLinkClicked me, data
                go data
                end

                This is all works fine.

                Now, I dropped your script onto the whole of my text file which includes my hyperlinked word


                on mouseUp me
                previousData = ["movie":the moviepath&the moviename, "label":the frameLabel]
                setpref("navigate_previous",string(previousData))
                end


                I then created a blank field text member and placed it near the foot of my destination marker from the hyperlink. Then dropped your code onto it:

                property previousData

                on beginsprite me
                previousData = value(getpref("navigate_previous"))
                myMem = sprite(me.spritenum).member
                if listp(previousData) then
                myMem.text = "Return to '"&previousData["label"]&"'"
                else
                myMem.text = ""
                end if
                end

                on mouseUp me
                if listp(previousData) then
                go(previousData["movie"],previousData["label"])
                end if
                end

                When I return and run from the hyperlinked word it jumps fine but the field text member is just blank.

                Is there something I've missed?

                Your help is much appreciated.

                regards

                Andy
                • 5. Re: Returning to a Hyperlink
                  duckets Level 1
                  what do you get if you type:

                  put getpref("navigate_previous")

                  into the message window?
                  What method did you use to put my code onto the blank text field in the destination movie? did you put the code into a new behaviour, and place the behaviour onto the text field? The fact that the text field is blank indicates that the code isn't being executed at all, since it should always put the text: "Return to '" into the text field.

                  If you didn't create a behaviour, you can do it like this:
                  select your text sprite (on the stage). Go to the property inspector and click the behaviour tab. Click the + button, and choose 'new behaviour'. Give the behaviour a name (as requested), then paste the code into the script window which opens.

                  You should then see your new behaviour listed in the behaviour tab of the property inspector, indicating that this behaviour (as well as having just been created in the cast) is now attached to your sprite.

                  - ben


                  • 6. Re: Returning to a Hyperlink
                    andyulrika_is_back Level 1
                    Hi Ben

                    I typed in
                    put getpref("navigate_previous") after hyperlinking and got a --void returned back to me.

                    As far as creating a new behaviour - I followed your steps again and had previously added a behaviour the same way, still no joy!

                    The script is a behaviour as opposed to a movie or parent in case you were wondering.

                    Any other suggestions?

                    kind regards

                    Andy


                    • 7. Re: Returning to a Hyperlink
                      duckets Level 1
                      In that case it suggests the 'setpref' function isn't being called. A good way of debugging if you're suspicious that a particular piece of code isn't being executed is to put an 'alert' or a 'put' statement into the code.

                      Eg, insert a line before the line containing 'setpref', which says:
                      alert("test!")

                      Now run your movie and try the link. If the alert doesn't show up, it means that code isn't being executed at all - as opposed to there being a bug in the code itself.

                      - ben
                      • 8. Re: Returning to a Hyperlink
                        andyulrika_is_back Level 1
                        Hi Ben

                        I inserted the alert message into the first 2 lines of code and there was no alert message. So, I don't think the script is running.

                        I also inserted the alert code into the target frame of the field text member and the alert message popped up - so I think this code is working ok.

                        Also, I just created a button and added the first 2 lines of code to check that the hyperlink text wasn't the culprit but there was no alert message displaying.

                        Apart from the code you gave me is there anything else I should have inserted. Like for example, create a folder called prefs? I'm really stumped at this now!

                        regards

                        Andy

                        • 9. Re: Returning to a Hyperlink
                          duckets Level 1
                          Perhaps the jump to the next movie is occuring before the 'mouseup' behaviour is triggered. Maybe you could change the behaviour containing the 2 lines of code to 'mousedown' instead of mouseup? in the hope that it is executed before the jump.

                          - Ben
                          • 10. Re: Returning to a Hyperlink
                            andyulrika_is_back Level 1
                            Hi Ben

                            I think the on MouseUp had something to do with it because now the script is displaying something in the targetted frame:

                            Return to '0'

                            I click on the link at it says:

                            Script error: String expected
                            go(previousData["movie"], previousData{"label"})

                            0

                            when I click on Debug it points to the line

                            go(previousData["movie"],previousData["label"])

                            Now, I looked up the Help menu and apparently 0 is reffering to the frame label not being named. However, I have a marker name there - Is that the same thing?

                            Any ideas how to fix?

                            Thanks again.

                            Andy