18 Replies Latest reply on Dec 10, 2006 6:02 AM by Newsgroup_User

    downloading a web image

    Level 7
      Hi,

      Not too long ago, I asked how to download an image from the web. The
      code I was given works great to download the file. And I've got a
      message for the usur to tell if the file was downloaded. I'm using
      netDone and netError.

      Problem is when the user clicks the download button, it's still has the
      netDone info from before. How can i tell Director to forget teh alst
      netDone and start from scratch?

      I' using
      netID = downLoadNetThing(" http://www.site.com/image.jpg, the moviePath
      & "image.jpg")

      the later use

      if ( netDone(netID) = true ) then

      if (netError(netID) = "OK" ) then
      member("message").text = "File downloaded OK."
      else
      member("weather-download message").text = "File could not be
      downloaded. Try again later."
      end if

      Thanks.


        • 1. Re: downloading a web image
          duckets Level 1
          How about setting netID to void, after the previous netdone is finished?
          • 2. Re: downloading a web image
            Level 7
            duckets wrote:

            > How about setting netID to void, after the previous netdone is finished?

            I tried setting netID to VOID (and 0)

            If I test in the message window while playin, I still get netDone(netID) = 1

            So, I don't know how or perhaps where to set the sttings back to 0.

            • 3. Re: downloading a web image
              Level 7
              Are you generating a new netID each time you download? If so you shouldn't
              have any problem. You don't specify if this code is in a frame loop or is
              only called once or ...

              Any net retrieval operation needs to be in a loop, not a repeat loop but a
              frame loop, this way the status can be monitored as the code cycles. Many
              call a net operation once and check for net done in the next line of code
              and wonder why nothing ever works. I don't think that's the case for you.
              I have found that it's neater and cleaner to use a case statement inside an
              exitFrame handler to represent each state of the net operation with
              properties for each piece of information that needs to persist through each
              frame cycle.

              Is netID a global variable in your case? Lngo will generate a new netID
              everytime you call downLoadNetThing but if you've declared it a global in
              one place and then call downloadnetthing where netID is local, the next time
              youa access netID from a different handler where it's declared as a global
              again, you'll still have the original netID (if you followed that, you
              probably didn't need me in the first place). Anyway, provide some more
              details, I'm sure it's an easy fix.

              --
              Craig Wollman
              Lingo Specialist
              Word of Mouth Productions
              212-928-9581

              www.wordofmouthpros.com
              "uni-student" <webforumsuser@macromedia.com> wrote in message
              news:457968AB.1ABD82F6@macromedia.com...
              > Hi,
              >
              > Not too long ago, I asked how to download an image from the web. The
              > code I was given works great to download the file. And I've got a
              > message for the usur to tell if the file was downloaded. I'm using
              > netDone and netError.
              >
              > Problem is when the user clicks the download button, it's still has the
              > netDone info from before. How can i tell Director to forget teh alst
              > netDone and start from scratch?
              >
              > I' using
              > netID = downLoadNetThing(" http://www.site.com/image.jpg, the moviePath
              > & "image.jpg")
              >
              > the later use
              >
              > if ( netDone(netID) = true ) then
              >
              > if (netError(netID) = "OK" ) then
              > member("message").text = "File downloaded OK."
              > else
              > member("weather-download message").text = "File could not be
              > downloaded. Try again later."
              > end if
              >
              > Thanks.
              >
              >


              • 4. Re: downloading a web image
                Level 7
                > Are you generating a new netID each time you download? If so you shouldn't
                > have any problem. You don't specify if this code is in a frame loop or is
                > only called once or ...

                I have a sprite behavior as follows:
                global netID

                on mouseUp me
                netID = downLoadNetThing(" http://www.site.com/image.jpg, the moviePath &
                "image.jpg")
                end

                How do I generate a new NetID each time? I tried setting it to 0. It didn't seem
                to work.


                > Is netID a global variable in your case?

                Yes, as above.

                > Lngo will generate a new netID
                > everytime you call downLoadNetThing but if you've declared it a global in
                > one place and then call downloadnetthing where netID is local, the next time
                > youa access netID from a different handler where it's declared as a global
                > again, you'll still have the original netID (if you followed that, you
                > probably didn't need me in the first place). Anyway, provide some more
                > details, I'm sure it's an easy fix.
                >
                OK, here's the full details, i hadtried to simplify it before:
                -- behavior attached to download button
                -- I have an editable text member on screen that the user can enter a URL.

                global netID

                on mouseUp me
                map = member("map").text

                if map = "" then
                alert "Please enter a URL first."
                else
                netID = downLoadNetThing(map, the moviepath & "map.jpg")
                end if

                member("message").text = "File downloading."

                end

                -- a new behavior attached to the message text sprite
                global netID

                on beginSprite me
                member("weather-download message").text = ""
                end

                on exitFrame
                if ( netDone(netID) = true ) then

                if (netError(netID) = "OK" ) then
                member("message").text = "File downloaded OK."
                else
                member("message").text = "File could not be downloaded. Try again
                later."
                end if

                else
                member("message").text = "File downloading."

                end if
                end

                So should I just not be decalring netID as a global?

                Thanks.

                • 5. Re: downloading a web image
                  Level 7
                  Oops, I should have proofed it before I pressed send.
                  Where I put:
                  member("weather-download message").text = ""
                  shoudl be
                  member("message").text = ""

                  Shouldn't make a difference, but just in case it confused things.

                  So in summary:
                  download is hapepning in 2 things:
                  * button that uses downloadNetThing
                  * message sprite (text) that checks if it has downloaded and inserts a message
                  either way.

                  What I want to do is when you clieck on teh download a second time, the text will
                  clear, it will say 'File downloading' and then give the final message when it's
                  done. Currently, after the first download, teh message is constantly 'File
                  downloaded OK' as it's not clearing it's last download from memory.

                  I had tried to set NetID to 0 a smentioned before. I took it out of the behaviors I
                  wrote here as it wasn't making a difference.

                  Thanks.

                  • 6. Re: downloading a web image
                    Level 7
                    The only way what you have will work is if there is significant time between
                    the mouseUp action and the exitFrame action. netDone won't return true
                    unless there has been time for the network to do it's thing. You seemed to
                    have missed a few of my points. Does that exitFrame handler loop? It seems
                    not to since there is no go to the frame in the handler. I know this isn't
                    addressing your issue so I'll get back to the matter at hand. How about
                    putting an alert just after your downloadnetthing call?

                    alert "Net ID = " & netID

                    I think you'll find that if you click several times, each time you'll get an
                    alert with a netID one number higher than the last. You absolutely need
                    netID declared as a global or you'll get an error "variable used before..."

                    Setting netID to void or 0 won't help since the latest call will always
                    replace the previous value whether it's a valid netID, a zero or void.

                    --
                    Craig Wollman
                    Lingo Specialist
                    Word of Mouth Productions
                    212-928-9581

                    www.wordofmouthpros.com
                    "uni-student" <webforumsuser@macromedia.com> wrote in message
                    news:457A1A02.D9735B06@macromedia.com...
                    > Oops, I should have proofed it before I pressed send.
                    > Where I put:
                    > member("weather-download message").text = ""
                    > shoudl be
                    > member("message").text = ""
                    >
                    > Shouldn't make a difference, but just in case it confused things.
                    >
                    > So in summary:
                    > download is hapepning in 2 things:
                    > * button that uses downloadNetThing
                    > * message sprite (text) that checks if it has downloaded and inserts a
                    > message
                    > either way.
                    >
                    > What I want to do is when you clieck on teh download a second time, the
                    > text will
                    > clear, it will say 'File downloading' and then give the final message when
                    > it's
                    > done. Currently, after the first download, teh message is constantly 'File
                    > downloaded OK' as it's not clearing it's last download from memory.
                    >
                    > I had tried to set NetID to 0 a smentioned before. I took it out of the
                    > behaviors I
                    > wrote here as it wasn't making a difference.
                    >
                    > Thanks.
                    >


                    • 7. Re: downloading a web image
                      Level 7
                      Hi Craig,

                      I did understand what you said before. Maybe because I just didn't confirm that,
                      you assumed the opposite. In my movie, in the scripting channel, there is an:
                      on exitFrame
                      go the frame
                      end

                      So, I have no problem in giving time for the download to happen and the message
                      update accordingly.

                      I just tried
                      alert "Net ID = " & netID

                      Yes, Net ID increases by 1 every time.

                      So, why is ' netDone(netID)' always true ? Since netID is always changing, I
                      would think the first tme download I'd 'get netDone(1)' which would only become
                      tue when downloading is done. Then when it checks the second tiem it would be
                      checking netDone(2) which i would assume would be 0 at some point.

                      Thanks.








                      • 8. Re: downloading a web image
                        Level 7
                        Well, it typically becomes true quickly when there is an error. Are you
                        getting an error or is netError = "OK"?

                        I'm guessing you're getting an error.

                        --
                        Craig Wollman
                        Lingo Specialist
                        Word of Mouth Productions
                        212-928-9581

                        www.wordofmouthpros.com
                        "uni-student" <webforumsuser@macromedia.com> wrote in message
                        news:457A377E.2E4707FF@macromedia.com...
                        > Hi Craig,
                        >
                        > I did understand what you said before. Maybe because I just didn't confirm
                        > that,
                        > you assumed the opposite. In my movie, in the scripting channel, there is
                        > an:
                        > on exitFrame
                        > go the frame
                        > end
                        >
                        > So, I have no problem in giving time for the download to happen and the
                        > message
                        > update accordingly.
                        >
                        > I just tried
                        > alert "Net ID = " & netID
                        >
                        > Yes, Net ID increases by 1 every time.
                        >
                        > So, why is ' netDone(netID)' always true ? Since netID is always changing,
                        > I
                        > would think the first tme download I'd 'get netDone(1)' which would only
                        > become
                        > tue when downloading is done. Then when it checks the second tiem it would
                        > be
                        > checking netDone(2) which i would assume would be 0 at some point.
                        >
                        > Thanks.
                        >
                        >
                        >
                        >
                        >
                        >
                        >
                        >


                        • 9. Re: downloading a web image
                          Level 7
                          On the other hand if you're internet connection is very fast and the images
                          are small, you could be completing the download faster than you think and
                          map.jpg is continually written over.



                          --
                          Craig Wollman
                          Lingo Specialist
                          Word of Mouth Productions
                          212-928-9581

                          www.wordofmouthpros.com
                          "forum.macromedia.com" <lingoboy@wordofmo.com> wrote in message
                          news:elddhc$4p9$1@forums.macromedia.com...
                          > Well, it typically becomes true quickly when there is an error. Are you
                          > getting an error or is netError = "OK"?
                          >
                          > I'm guessing you're getting an error.
                          >
                          > --
                          > Craig Wollman
                          > Lingo Specialist
                          > Word of Mouth Productions
                          > 212-928-9581
                          >
                          > www.wordofmouthpros.com
                          > "uni-student" <webforumsuser@macromedia.com> wrote in message
                          > news:457A377E.2E4707FF@macromedia.com...
                          >> Hi Craig,
                          >>
                          >> I did understand what you said before. Maybe because I just didn't
                          >> confirm that,
                          >> you assumed the opposite. In my movie, in the scripting channel, there is
                          >> an:
                          >> on exitFrame
                          >> go the frame
                          >> end
                          >>
                          >> So, I have no problem in giving time for the download to happen and the
                          >> message
                          >> update accordingly.
                          >>
                          >> I just tried
                          >> alert "Net ID = " & netID
                          >>
                          >> Yes, Net ID increases by 1 every time.
                          >>
                          >> So, why is ' netDone(netID)' always true ? Since netID is always
                          >> changing, I
                          >> would think the first tme download I'd 'get netDone(1)' which would only
                          >> become
                          >> tue when downloading is done. Then when it checks the second tiem it
                          >> would be
                          >> checking netDone(2) which i would assume would be 0 at some point.
                          >>
                          >> Thanks.
                          >>
                          >>
                          >>
                          >>
                          >>
                          >>
                          >>
                          >>
                          >
                          >


                          • 10. Re: downloading a web image
                            Level 7
                            "forum.macromedia.com" wrote:

                            > On the other hand if you're internet connection is very fast and the images
                            > are small, you could be completing the download faster than you think and
                            > map.jpg is continually written over.

                            Maybe I should test with a larger image. I'm not getting any error message. Just
                            not getting any indication that it has reloaded a new image. I want to give the
                            user a signal that the new image has downloaded.

                            But, even if I test netDone in the message window, I alwasy get a value of 1,
                            even if I close Director and reopen it without doing any download.

                            .



                            • 11. Re: downloading a web image
                              Level 7
                              put netDone ()

                              without a netID will always give a 1 in the message window. Are you
                              including the netID?

                              So, you're getting File downloaded OK in your message text every time?

                              Modify your message to read "File downloaded from netID: " & netID & " OK"
                              so you can at least see that each netID is completing properly
                              --
                              Craig Wollman
                              Lingo Specialist
                              Word of Mouth Productions
                              212-928-9581

                              www.wordofmouthpros.com
                              "uni-student" <webforumsuser@macromedia.com> wrote in message
                              news:457A3DFB.DA76FBAC@macromedia.com...
                              > "forum.macromedia.com" wrote:
                              >
                              >> On the other hand if you're internet connection is very fast and the
                              >> images
                              >> are small, you could be completing the download faster than you think and
                              >> map.jpg is continually written over.
                              >
                              > Maybe I should test with a larger image. I'm not getting any error
                              > message. Just
                              > not getting any indication that it has reloaded a new image. I want to
                              > give the
                              > user a signal that the new image has downloaded.
                              >
                              > But, even if I test netDone in the message window, I alwasy get a value of
                              > 1,
                              > even if I close Director and reopen it without doing any download.
                              >
                              > .
                              >
                              >
                              >


                              • 12. Re: downloading a web image
                                Level 7
                                Have you thought of creating a cue so that subsequent clicks don't
                                continually create net requests and only one is handled at a time? I
                                beleive that there used to be a limit (spoken or unspoken, I don't know) of
                                four net requests at a time.

                                --
                                Craig Wollman
                                Lingo Specialist
                                Word of Mouth Productions
                                212-928-9581

                                www.wordofmouthpros.com
                                "uni-student" <webforumsuser@macromedia.com> wrote in message
                                news:457A3DFB.DA76FBAC@macromedia.com...
                                > "forum.macromedia.com" wrote:
                                >
                                >> On the other hand if you're internet connection is very fast and the
                                >> images
                                >> are small, you could be completing the download faster than you think and
                                >> map.jpg is continually written over.
                                >
                                > Maybe I should test with a larger image. I'm not getting any error
                                > message. Just
                                > not getting any indication that it has reloaded a new image. I want to
                                > give the
                                > user a signal that the new image has downloaded.
                                >
                                > But, even if I test netDone in the message window, I alwasy get a value of
                                > 1,
                                > even if I close Director and reopen it without doing any download.
                                >
                                > .
                                >
                                >
                                >


                                • 13. Re: downloading a web image
                                  Level 7
                                  > without a netID will always give a 1 in the message window. Are you
                                  > including the netID?

                                  Yes. In the message window, I tried 'put netDone(netID)' and put 'netDone(10)'
                                  before netID reached 10 and got a result of 1 every time.

                                  > So, you're getting File downloaded OK in your message text every time?

                                  That's right. I wanted it to switch to 'File downloading' even for a brief
                                  moment, just to show something new had happened.

                                  > Modify your message to read "File downloaded from netID: " & netID & " OK"
                                  > so you can at least see that each netID is completing properly

                                  I changed the nehavior so the text now displays the number of times a file has
                                  been downloaded using netID.

                                  It is still immediate, but at least there's some indication a new file has been
                                  downloaded.


                                  • 14. Re: downloading a web image
                                    Level 7
                                    > Have you thought of creating a cue so that subsequent clicks don't
                                    > continually create net requests and only one is handled at a time? I
                                    > beleive that there used to be a limit (spoken or unspoken, I don't know) of
                                    > four net requests at a time.

                                    No, haven't thought about this. So, do I check netDone and only issue a new
                                    request if the last one is complete?


                                    • 15. Re: downloading a web image
                                      Level 7
                                      I'd like to send you a file I put together that includes the cue I'm talking
                                      about. Although I don't quite know the exact issue in your case I've
                                      mentioned what I think it is because of what I see so far with your code.
                                      Mainly, the code needs have time for each event to happen. When I do net
                                      operations I do everything one step at a time in the same behavior so in my
                                      example I've put together, all of the code is in the same behavior as the
                                      mouseUp. You can access all of your text members from there are it
                                      compartmentalizes your operations to give it a more OOP approach.

                                      I could post the code but I'd rather send you the file so that you have a
                                      working version that you don't have to assemble yourself.

                                      --
                                      Craig Wollman
                                      Lingo Specialist
                                      Word of Mouth Productions
                                      212-928-9581

                                      www.wordofmouthpros.com
                                      "uni-student" <webforumsuser@macromedia.com> wrote in message
                                      news:457A434A.3B189211@macromedia.com...
                                      >> Have you thought of creating a cue so that subsequent clicks don't
                                      >> continually create net requests and only one is handled at a time? I
                                      >> beleive that there used to be a limit (spoken or unspoken, I don't know)
                                      >> of
                                      >> four net requests at a time.
                                      >
                                      > No, haven't thought about this. So, do I check netDone and only issue a
                                      > new
                                      > request if the last one is complete?
                                      >
                                      >


                                      • 16. Re: downloading a web image
                                        Level 7
                                        Of course, I'd love to see your whole movie to be able to tell you exactly
                                        what's not right.

                                        --
                                        Craig Wollman
                                        Lingo Specialist
                                        Word of Mouth Productions
                                        212-928-9581

                                        www.wordofmouthpros.com
                                        "uni-student" <webforumsuser@macromedia.com> wrote in message
                                        news:457A434A.3B189211@macromedia.com...
                                        >> Have you thought of creating a cue so that subsequent clicks don't
                                        >> continually create net requests and only one is handled at a time? I
                                        >> beleive that there used to be a limit (spoken or unspoken, I don't know)
                                        >> of
                                        >> four net requests at a time.
                                        >
                                        > No, haven't thought about this. So, do I check netDone and only issue a
                                        > new
                                        > request if the last one is complete?
                                        >
                                        >


                                        • 17. Re: downloading a web image
                                          Level 7
                                          "forum.macromedia.com" wrote:

                                          > Of course, I'd love to see your whole movie to be able to tell you exactly
                                          > what's not right.

                                          Hi Craig,

                                          Thanks for all your help. At the moment, seems to be working OK.

                                          In terms of seeing thw whole movie, it's mothing too fancy at this stage. I've
                                          pretty much summed up whats happening here
                                          * editible text sprite where you enter the URL
                                          * button to download the image from above URL
                                          * text member sitting next to the download button that gives user feedback on
                                          download status.

                                          I'll let you know if I need that other info.

                                          You have been a great help. Much appreciated

                                          • 18. Re: downloading a web image
                                            Level 7
                                            No problem

                                            --
                                            Craig Wollman
                                            Lingo Specialist
                                            Word of Mouth Productions
                                            212-928-9581

                                            www.wordofmouthpros.com
                                            "uni-student" <webforumsuser@macromedia.com> wrote in message
                                            news:457BEC5A.D89C3BA1@macromedia.com...
                                            > "forum.macromedia.com" wrote:
                                            >
                                            >> Of course, I'd love to see your whole movie to be able to tell you
                                            >> exactly
                                            >> what's not right.
                                            >
                                            > Hi Craig,
                                            >
                                            > Thanks for all your help. At the moment, seems to be working OK.
                                            >
                                            > In terms of seeing thw whole movie, it's mothing too fancy at this stage.
                                            > I've
                                            > pretty much summed up whats happening here
                                            > * editible text sprite where you enter the URL
                                            > * button to download the image from above URL
                                            > * text member sitting next to the download button that gives user feedback
                                            > on
                                            > download status.
                                            >
                                            > I'll let you know if I need that other info.
                                            >
                                            > You have been a great help. Much appreciated
                                            >