5 Replies Latest reply on Nov 30, 2007 4:26 PM by robdillon

    Inserting JavaScript into MX2004 FLA file

    SteveH59 Level 1
      Hello

      I am trying to write some JavaScript to ensure that when the site visitor goes to the 'contact' page, the cursor is already in place in the form field (name).

      I understand that to do this I need to use fscommand in the Actions panel followed by the JavaScript which I have.

      However, when I highlight the 'Name' field on the , that is, the input text box, so that it has a blue frame round it, the Actions panel tells me that the 'current selection cannot have actions applied to it'.

      How would it be best to get round this problem, please?

      Thank you.

      Steve
        • 1. Re: Inserting JavaScript into MX2004 FLA file
          robdillon Most Valuable Participant
          If this Name field is in the Flash movie then you want to use actionscript to set the focus and cursor position.

          Just put this in a frame action space where the input text space is located:

          Selection.setFocus("inputFieldInstanceName");
          Selection.setSelection(0,0);
          • 2. Re: Inserting JavaScript into MX2004 FLA file
            SteveH59 Level 1
            Hello Rob

            Many thanks for your reply.

            That sounds like a lot easier than using JavaScript, but when I click on the input text box for name (the first field in my form and where I would like the focus to be), the Actions Panel tells me that the current selection cannot have anything applied to it.

            Is there a way to overcome this?

            Thanks again for your help.

            Steve
            • 3. Re: Inserting JavaScript into MX2004 FLA file
              robdillon Most Valuable Participant
              Hi Steve,

              Yes, it sounds like you are using CS3 with AS3 enabled. AS3 won't let you apply code directly to objects. You want to write the code to a frame action space in the timeline. Be sure to name the input text object.
              • 4. Re: Inserting JavaScript into MX2004 FLA file
                SteveH59 Level 1
                Hello Rob

                Many thanks again for your post.

                I'm actually using MX2004, but I am trying to customise a site I have recently bought and maybe it was built using a later version.

                Please excuse my ignorance but what does it mean 'to write the code to a frame action space in the timeline'?

                How would I go about inserting the setFocus script to a frame action space. If it is too lengthy to explain, maybe there's a link I could visit?

                Thanks again.

                Steve
                • 5. Re: Inserting JavaScript into MX2004 FLA file
                  robdillon Most Valuable Participant
                  In MX2004 you can apply actionscript to either an object: a movieClip or a button, or to a keyframe in the timeline. To attach code to the timeline, add a new layer, I use the top of the timeline for this. Then select the first keyframe in that new layer. Open the Actions window. At the top left of that window it should say "Actions - Frame". Any code that you write to this space will be available to the whole movie.