5 Replies Latest reply on Mar 21, 2007 3:18 AM by Newsgroup_User

    Another XML question

    wgb14 Level 1
      Hi all,

      I wonder if you can help me with the following: I have a cast member that is fed with text phrases from an XML database.
      Once the phrases have been loaded into the cast member i have a script that feeds the first line of the cast member with the phrases (name: questions) to another cast member of the stage.

      member("Q").text = member("questions").line[1]

      Now On my stage i also have a button that should load the next line of the member questions to the member Q untill there are no lines at all. I suspect that i should load all the lines of the member questions into a list and then pull out each phrase from the list subsequently untill there are no phrases at all. However, i am not sure how to do that! Any ideas?

      Many thanks
        • 1. Re: Another XML question
          wgb14 Level 1
          This is what i have so far:

          on mousedown

          lista = []

          texta = the text of member ("questions")

          maxLines = member("questions").line.count

          repeat with i = 2 to maxLines
          add lista, line i of texta
          end repeat

          member ("Q").text = getAt(lista, 1)

          However i am unsure how to pick up the items in the list and feed them in the Q cast member every time that the mousedown event is called!

          Any ideas?

          Thanks
          • 2. Re: Another XML question
            Level 7
            I'm not sure why you skip the first line of text of member("questions")
            when building your list (perhaps because you've already assigned the
            question?)
            I would suggest something like the following:
            --
            property myQuestionList

            on beginSprite me
            myQuestionList = []
            tText = member("questions").text
            maxLines = tText.line.count
            repeat with i = 1 to maxLines
            myQuestionList.append(tText.line )
            end repeat
            member("Q").text = myQuestionList[1]
            end

            on mouseUp me
            tPos = myQuestionList.getPos(member("Q").text)
            if tPos < count(myQuestionList) then
            member("Q").text = myQuestionList[tPos + 1]
            else
            -- no more available questions
            end if
            end

            However, I think the logic for displaying questions might better be
            associated with the text sprite that displays the questions (objects
            should perhaps be as responsible for themselves as possible).
            Then the button could simply tell the question display object to display
            the next question:
            -- question display (#text sprite)
            property myQuestionList
            property myCurrentQuestion
            property myMember

            on beginSprite me
            myMember = sprite(me.spriteNum).member
            myQuestionList = []
            tText = member("questions").text
            maxLines = tText.line.count
            repeat with i = 1 to maxLines
            myQuestionList.append(tText.line
            )
            end repeat
            myCurrentQuestion = 0
            me.mDisplayNextQuestion()
            end

            on mDisplayNextQuestion me
            tPos = myCurrentQuestion + 1
            if tPos < count(myQuestionList) then
            myMember.text = myQuestionList[tPos]
            myCurrentQuestion = tPos
            else
            -- no more available questions
            end if
            end

            -- button sprite:
            on mouseUp me
            _movie.sendAllSprites(#mDisplayNextQuestion)
            end
            • 3. Re: Another XML question
              wgb14 Level 1
              Hi, you code seems to work but there is an error in this line

              myQuestionList.append(tText.line)

              what is wrong here?

              Thanks
              • 4. Re: Another XML question
                Level 7
                > Hi, you code seems to work but there is an error in this line
                >
                > myQuestionList.append(tText.line)
                >
                > what is wrong here?

                I'm not seeing where you're getting that line from. In both example
                implementations I posted that line is:
                myQuestionList.append(tText.line )
                • 5. Re: Another XML question
                  Level 7
                  I suspect he is using the web forum and it is translating your code as
                  beginning italics.... try it like this:


                  myQuestionList.append(tText.line[ i ])