7 Replies Latest reply on Sep 6, 2006 9:36 AM by Newsgroup_User

    Retrieve changing values from TextInput Flash Component

    tayl
      Hi,

      I've been banging my head against the wall with this one....

      I've placed aTextInput Flash Component on the stage which reads/displays a value from an external text file. So far so good.

      If I enter new text during run-time - editable is set to true - the TextInput component updates to reflect what I've typed. BUT, how do I retrieve that text to a variable? (I need to save the new value back to the external text file).

      Current code:
      myfieldtext = sprite(51).text
      And eventPassMode is set to passAlways

      this retrieves the initial value regardless of what I type.

      Any help appreciated!

        • 1. Re: Retrieve changing values from TextInput Flash Component
          Level 7
          How are you assigning the text at startup?

          --
          Rob
          _______
          Rob Dillon
          Adobe Community Expert
          http://www.ddg-designs.com
          412-243-9119

          http://www.macromedia.com/software/trial/
          • 2. Re: Retrieve changing values from TextInput Flash Component
            tayl Level 1
            on prepareMovie
            clearGlobals
            setFields
            end


            ----------------------------------------------------------------------------------
            --set the contents of the fields to the values in the text file called 'untitled.txt'
            ----------------------------------------------------------------------------------
            on setFields
            fileNm = the moviePath &'untitled.txt'
            sprite( member("myInput") ).text = getValueFromFile(fileNm, "SERIAL")
            • 3. Re: Retrieve changing values from TextInput Flash Component
              Level 7
              I'm not sure if this all helps, but I had to make a flash name input box
              recently. I was getting all sorts of weird results trying to get the text
              out of flash. It was giving me all the font info etc, and I just needed the
              name. So what I ended up doing is when they were done entering the text, I
              put the text into a variable within flash, then pulled the data from that
              variable rather than striaght out of the text.

              in director, in the behaviour attached to the flash sprite:
              myText = sprite("nameInput").getVariable( "myNameString", True)
              where the sprite is named "nameInput". It seems better to name the sprite
              and refer to it that way than using the sprite number, such as sprite(51).

              In flash I have the text input field named "textInput", and the following
              code attached to the save button. You may have to use a different event,
              like when they text input loses focus.

              on (release) {
              var myNameString = "";
              myNameString = textInput.text
              trace(myNameString)
              getURL('event:doEvent,1')
              }

              Timm

              "tayl" <webforumsuser@macromedia.com> wrote in message
              news:edjutm$ptl$1@forums.macromedia.com...
              > Hi,
              >
              > I've been banging my head against the wall with this one....
              >
              > I've placed aTextInput Flash Component on the stage which reads/displays a
              > value from an external text file. So far so good.
              >
              > If I enter new text during run-time - editable is set to true - the
              > TextInput
              > component updates to reflect what I've typed. BUT, how do I retrieve that
              > text
              > to a variable? (I need to save the new value back to the external text
              > file).
              >
              > Current code:
              > myfieldtext = sprite(51).text
              > And eventPassMode is set to passAlways
              >
              > this retrieves the initial value regardless of what I type.
              >
              > Any help appreciated!
              >
              >
              >


              • 4. Re: Retrieve changing values from TextInput Flash Component
                tayl Level 1
                Hi, thanks for replying! but still not working

                There doesn't seem to be an appropriate handler for attaching the script :
                myText = sprite("nameInput").getVariable( "myNameString", True)
                to the Flash TextInput component?

                Also is "myNameString" a global variable, & if so, how/where is it initialised? When the user tabs out of the field? Not sure how you do that in Director?

                Thanks, Andrea
                • 5. Re: Retrieve changing values from TextInput Flash Component
                  Level 7
                  Hi Andrea,

                  I can't find a way to make this not work. I'm suspecting that there may
                  be a problem with the way that you are assigning the text to the member
                  in the first place.

                  The contents of a a textInput component are not assigned to a variable
                  in Director, so using getVariable() won't do anything for you. Simply
                  asking for the sprite's text property value should give you what you
                  want.

                  Can you explain how you are assigning the text?

                  --
                  Rob
                  _______
                  Rob Dillon
                  Adobe Community Expert
                  http://www.ddg-designs.com
                  412-243-9119

                  http://www.macromedia.com/software/trial/
                  • 6. Re: Retrieve changing values from TextInput Flash Component
                    tayl Level 1
                    Text is assigned using an external text file - using FileIO:

                    fileNm = the moviePath &"untitled.txt"
                    sprite( member("myname") ).text = getValueFromFile(fileNm, "NAME")

                    This script is in an 'on prepareMovie' movie script & it works perfectly.

                    I can edit the text field. BUT, the following script returns the ORIGINAL value regardless of any user changes:
                    put sprite( member("myname") ).text

                    This script is attached to a 'save' button (on mouseUp).

                    Does that help?
                    • 7. Re: Retrieve changing values from TextInput Flash Component
                      Level 7
                      Yes,

                      what does this mean - sprite( member("myname") ).text ?

                      and what does the function "getValueFromFile()" do? Is this a function
                      that you wrote? It's not a fileIO function.

                      You can set the text of a member by assigning some body of text to it. I
                      have no idea what "sprite( member("myname") ).text" does. In my copy of
                      Director it generates an error.

                      If you have an existing text member, then you can import text from an
                      external file using fileIO, something like this:

                      -------------
                      on prepareMovie
                      myFile = new(xtra "fileIO")
                      fileName = the moviePath & "untitled.txt"
                      openFile(myFile,fileName,1)
                      thisFile = readFile(myFile)
                      member("myname").text = thisFile
                      closeFile(myFIle)
                      myFile = 0
                      end
                      -----------

                      This is a really bare bones use of fileIO. There is no error checking at
                      all. It does work in my test. The text of member "myname" can be changed
                      and will return the text change when queried.

                      --
                      Rob
                      _______
                      Rob Dillon
                      Adobe Community Expert
                      http://www.ddg-designs.com
                      412-243-9119

                      http://www.macromedia.com/software/trial/