9 Replies Latest reply on Jun 20, 2011 9:23 AM by jchunick

    send focus on the stage

    wgb14 Level 1

      Hi

       

      1) I have the following code

       

       

      on mouseup me

        sound(1).play( member("typewriter1"))

       

        tFocus = _movie.keyBoardFocusSprite

        tText = sprite(tFocus).text

        c = tText.length

        if c <> 0 then

          tText = tText & numtochar(32)

          sprite(tFocus).text = tText

        else

          beep

        end if

      end

       

       

      Everything works fine when the flash textarea component is in the same movie. However when I am trying this

       

      tFocus = window("stage").movie.keyBoardFocusSprite

       

      I am getting tfocus = - 1. Any ideas how to send the focus to the stage?

       

      2) Also, the following code inputs a predefined letter in the flash component. It works fine, but the inseration point (IBeam cursor) does not move at the end of each letter (as it should be). Any ideas how to fix this?

       

       

       

      property myKey

      property pme,displayField

       

      on getpropertydescriptionlist me

        a = [:]

        addprop a, #myKey, [#default : sprite(the currentspritenum).member.name, #format:#string, #comment : "what key do I put into the field?"]

        return a

      end

       

      on beginsprite me

        pme = sprite(me.spritenum)

      end

       

      on mouseUP me

       

        puppetSound 1, "typewriter1"

       

        --displayField = window("stage").movie.member(which_field)

       

        displayField = _movie.keyboardFocusSprite

       

      end

       

      One last question:

       

      3) In the same textarea I am trying to delete the last character using the code below. Again it doesn't work. Any ideas?

       

       

      global which_field

       

      on mousedown

        puppetSound 1, "typewriter1"

       

        tFocus = _movie.keyBoardFocusSprite

       

        tText = sprite(tFocus).text

       

        c = tText.length

       

        if c <> 0 then

          tText.char[c].delete()

        else

          beep

        end if

       

      END

        • 1. Re: send focus on the stage
          Tols (UK) Level 1

          I've never used Flash Components to be frank but I'd imagine the problem with (3) is that ttext is just a text variable and isn't an object referencing the textfield's contents indefinitely. so i would try something like

           

           

          if c <> 0 then

              sprite(tFocus).member.text=ttext.char[1..c-1]

            else

              beep

            end if

           

           

           

          As for 2, set the selstart and selend to the length of the field's current text.

           

           

          As for 1, i'm not sure what you mean actually.

          Everything works fine when the flash textarea component is in the same movie.

          same movie as what?

          • 2. Re: send focus on the stage
            Sean_Wilson Adobe Community Professional
            As for 1, i'm not sure what you mean actually.

            Everything works fine when the flash textarea component is in the same movie.

            same movie as what?

            The OP is using a MIAW - something that wasn't clearly explained.

             

            Also, he posted to a different forum where all of his questions were answered. Unfortunately he never bothered to get back here and flag the question as answered or update the thread - a good reason to stick to one forum at a time, since it saves this sort of confusion.

            • 3. Re: send focus on the stage
              wgb14 Level 1

              Sorry for the double posts, but I figured out 1, and 3 myself.... The answers are similar to what Tols suggests. The second still troubles me... Here is the compelte code for it... There are no selstart and selend for the textarea flash component. Any ideas?

               

               

              global accent,re1,tFocus
              property myKey
              property pme
              
              on getpropertydescriptionlist me
                a = [:]
                addprop a, #myKey, [#default : sprite(the currentspritenum).member.name, #format:#string, #comment : "what key do I put into the field?"]
                return a
              end
              
              on beginsprite me
                pme = sprite(me.spritenum)
                accent = 0   --set the intial value for the accentation variable  
                re1 = "(omikron)|(omega)|(ipsilon)"
              end
              
              on mouseUP me
                
                puppetSound 1, "typewriter1"
                accentuation
                if sprite(53).text = "Caps:On" then  
                  oString=new(xtra "mevString", RegExp_Replace(myKey, re1, "", "gi"))  
                  oString.mevcToUpper()  
                  window("stage").movie.sprite(tFocus).text = window("stage").movie.sprite(tFocus).text&oString.mevcGetString()
                else
                  if sprite(53).text = "Caps:Off" then
                    window("stage").movie.sprite(tFocus).text = window("stage").movie.sprite(tFocus).text & RegExp_Replace(myKey, re1, "", "gi")
               
                  end if 
                end if 
              end

              • 4. Re: send focus on the stage
                Tols (UK) Level 1

                Haven't tried this but

                 

                try

                 

                  window("stage").movie.sprite(tFocus).member.text

                 

                instead of

                 

                window("stage").movie.sprite(tFocus).text

                 

                and put

                 

                set the selstart to (sprite(tfocus).member.text).length

                 

                at the end of the mouseup handler - this should put the cursor at the 

                end.

                 

                No?

                1 person found this helpful
                • 5. Re: send focus on the stage
                  wgb14 Level 1

                  set the selstart to (sprite(tfocus).member.text).length

                   

                  That doesn't work either....I am searching the web for almost 3 hours now but nothign so far....

                  • 6. Re: send focus on the stage
                    Tols (UK) Level 1

                    ok due to my inexperience in flash components i just tested that code 

                    I suggested and it worked fine for me.

                     

                    by fine I mean that the cursor got put at the end of the line, after 

                    the character that the mouseup inserted.

                    (Without the selstart line I suggested the cursor is left at the 

                    penultimate character.)

                     

                    What is the character that you are inserting, i just used a single 

                    character 'j'

                     

                    Perhaps stick an updatestage before the selstart line - they often fix 

                    things!

                     

                    Or maybe its a miaw issue, but you seem to referencing the stage so I 

                    presume that's not the case.

                    1 person found this helpful
                    • 7. Re: send focus on the stage
                      wgb14 Level 1

                      Here is the solution in case you need it. I had to search through the help file of Actionscript 2 to find this. 

                       

                      sprite(54).Selection.setSelection(sprite(54).text.length, sprite(54).text.length)

                      • 8. Re: send focus on the stage
                        BigDaddy Level 1

                        Hi,

                         

                        Since you were successful with the aid of the forum members, I hope that someone can help me with a similar situation.

                         

                        I'm trying to get the position of the cursor 'within a string' in a field member, in order to delete characters.

                         

                        For example, if member("text string").text = "abcdeggh", I want to delete character 6. It would be 'easier' if I knew that the cursor was

                        between characters 5-6 or characters 6-7. the difference is delete versus backspace. I don't want to backspace eliminate "h,g, and g".

                        I want to delete "g" (character 6) then type "f".

                         

                        Thanks for any help you can give.

                         

                        BigDaddy