6 Replies Latest reply on Jul 20, 2007 8:35 AM by Newsgroup_User

    Displaying text dynamically

    Sarawinder Level 1
      Hi

      I want to display text dynamically on the stage

      e.g

      When I click mouse first time its should display " this is the first click" and second time " this is the second clik" and so on.

      Can someone help me with the code here.

        • 1. Re: Displaying text dynamically
          Level 7
          Hi Sarawinder,

          Depending on which ActionScript version you're using the code will
          differ. For ActionScript 2.0, it will look something like this:

          _root.createTextField('mouseText',_root.getNextHighestDepth,0,0,100,20);
          _root.mouseText.autoSize='left';
          _root.clickCounter=0;
          Mouse.addListener(this);
          function onMouseDown() {
          switch (_root.clickCounter) {
          case 1 : _root.mouseText.text="this is the first click"; break;
          case 2 : _root.mouseText.text="this is the second click"; break;
          case 3 : _root.mouseText.text="this is the third click"; break;
          }
          _root.clickCounter++;
          }

          For ActionScript 3.0, there's more possibility of mucking things up.
          More power=more opportunity for errors. But if you feel you have enough
          experience then give it a try. Here's the same code for Flash CS3:

          import flash.text.*;
          import flash.events.*;
          var mouseText:TextField=new TextField();
          mouseText.autoSize='left';
          this.addChild(mouseText);
          var clickCounter:uint=0;
          stage.addEventListener(MouseEvent.MOUSE_DOWN,this.onMouseDown);
          function onMouseDown(eventObj:MouseEvent) {
          switch (_this.clickCounter) {
          case 1 : this.mouseText.text="this is the first click"; break;
          case 2 : this.mouseText.text="this is the second click"; break;
          case 3 : this.mouseText.text="this is the third click"; break;
          }
          this.clickCounter++;
          }//onMouseDown

          Good luck,
          Patrick

          --
          http://www.baynewmedia.com
          Faster, easier, better...ActionScript development taken to new heights.
          Download the BNMAPI today. You'll wonder how you ever did without it!
          Available for ActionScript 2.0/3.0.

          Sarawinder wrote:
          > Hi
          >
          > I want to display text dynamically on the stage
          >
          > e.g
          >
          > When I click mouse first time its should display " this is the first click"
          > and second time " this is the second clik" and so on.
          >
          > Can someone help me with the code here.
          >
          >
          >


          • 2. Re: Displaying text dynamically
            Sarawinder Level 1
            Thanks patrick I am using the AS 2 version and its giving me this error

            **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Type mismatch.
            _root.createTextField("mouseText",_root.getNextHighestDepth,0,0,100,20);

            Total ActionScript Errors: 1 Reported Errors: 1

            • 3. Re: Displaying text dynamically
              Sarawinder Level 1
              Thanks patrick I am using the AS 2 version and its giving me this error

              **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Type mismatch.
              _root.createTextField("mouseText",_root.getNextHighestDepth,0,0,100,20);

              Total ActionScript Errors: 1 Reported Errors: 1

              • 4. Re: Displaying text dynamically
                craus Level 1
                change to: _root.getNextHighestDepth() with the parenthesis.
                • 5. Re: Displaying text dynamically
                  everynewday
                  You could also do something to this effect:

                  var counter:Number = 0;
                  var mouseListener:Object = new Object();
                  mouseListener.onMouseDown = function() {
                  myText.text = "This is click " + counter;
                  counter++;
                  };
                  Mouse.addListener(mouseListener);

                  This code assumes you have a text field called "myText" on the stage.
                  • 6. Re: Displaying text dynamically
                    Level 7
                    Yes, what craus said....getNextHighestDepth is a function so it should
                    be _root.getNextHighestDepth(). Sorry about that.

                    Good luck,
                    Patrick

                    Sarawinder wrote:
                    > Thanks patrick I am using the AS 2 version and its giving me this error
                    >
                    > **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Type mismatch.
                    > _root.createTextField("mouseText",_root.getNextHighestDepth,0,0,100,20);
                    >
                    > Total ActionScript Errors: 1 Reported Errors: 1
                    >
                    >
                    >

                    --
                    http://www.baynewmedia.com
                    Faster, easier, better...ActionScript development taken to new heights.
                    Download the BNMAPI today. You'll wonder how you ever did without it!
                    Available for ActionScript 2.0/3.0.