6 Replies Latest reply on Jan 1, 2010 10:17 PM by ASJoke

    this.creatTextField() help

    ASJoke Level 1

      Hello;

       

      I am trying to create a tabular layout of textFields by running a function that takes a list

      of strings and uses a for loop to create text fields. But as I have it it is not working.

       

      Here is a snippet of code:

       

      function buildPLayList(playListTitles:String):Void
               {
                var playList:Array = new Array()
                    playList = playListTitles.split('|');
                trace(playList) // -> expected output
                var strOut:String = '';
                var origin_x:Number = 75;
                var origin_y:Number = 64;
                var baseWdth:Number = 25;
                var baseHght:Number = 30;
                var i:Number = 0;
                for(i = 0; i < playList.length; i++)
                   {
                    playListInfo[i] = new Object();
                    playListInfo[i].name = "INFO"+i;
                    // x, y, width, height
                    this.createTextField(playListInfo[i].name, this.getNextHighestDepth(), 0, 0, 0, 0) // <<--
                    playListInfo[i].name._x = origin_x // <<-- since --.name is a string, I don't think this is working
                    playListInfo[i].name._y = origin_y*(i+1)
                    playListInfo[i].name._width = baseWdth
                    playListInfo[i].name._height = baseHght
                    playListInfo[i].name.text = "Info";
                    playListInfo[i].name.setTextFormat(playListInfoForm);
                    playListInfo[i].name.onPress = function()
                                                   {
                                                    var target = playListPaths[i];
                                                    fscommand("alert", playList[i])
                                                    // call javascript alert(playList[i])
                                                   }
                    playListInfo[i].name.onRollOver = function()
                                                       {
                                                        // change text color
                                                       }
                    playListInfo[i].name.onRollOut = function()
                                                       {
                                                        // change text color to original
                                                       }

      // similar code for two more textFields in each row

       

      strOut += playListInfo[i].name.text+" : "+playListPlay[i].name.text+" : "+playListTitle[i].name.text+"\n"; // **

      //strOut += playListInfo[i].name+" : "+playListPlay[i].name+" : "+playListTitle[i].name+"\n"; // trace produces expected output
                   }
                trace(strOut) // ** -> undefined : undefined : undefined
               }

      Is there a way to do this? I can use html, and have done it successfully in a loop, but rollover effects seem to be a lot

      more obscure using styleSheets.

       

      Thank you for time and attention

      Jk

        • 1. Re: this.creatTextField() help
          ASJoke Level 1

          I found the global function eval()....Yay, it answers a question I have had before.

          so the way it goes is:  eval(playListInfo[i].name)._x = origin_x .... etc.

           

          How ever I am still not getting the event handlers to respond to onPress and

          onRollOver/ onRollOut. Can these be applied to textFields? If not how else

          could this be done?

           

          Thank you for time and attention

          JK

          • 2. Re: this.creatTextField() help
            Rothrock Level 5

            eval() has generally been replaced with the array notation and there are times where you can't use eval, so I would recommend forgetting that you learned it.

             

            So you could probably get the same result with:

             

            this[playListInfo[i].name]._x

             

            Or if you need to put some strings together:

             

            this["someStringStem"+i]

             

            Or if you had something inside of the clips in your playListInfo array

             

            this[playListInfo[i].name]["someChildName"]._x

             

            In AS2 there are times where the compiler "looses" scope. An easy way to deal with this is to add at the top of your code:

             

            var home:MovieClip=this;

             

            So that anytime you need a reference to the main timeline (or the one where you code is you can do this:

             

            home["someString"+someVariable]

             

            There are times where

             

            this["someString"+someVariable]

             

            Could not return what you expect because "this" isn't what you think it will be. But home (or whatever you call it) will be!

             

            Check the help files to see if the TextField class has those events. I don't think they do. I think you are new to AS, so I'll suggest using the AS language reference part of the help files. All the classes are there in alphabetic order so it is easy once you know which class you are dealing with. So it you are working with TextFields go directly to that class and you can see all the methods, properties and events available for that class.

             

            You can create a textfield inside a movieclip and then register the events to movieclip.

            • 3. Re: this.creatTextField() help
              ASJoke Level 1

               

              Well, thank you for the info, I will keep all this in mind. In my app,

              eval seems to be working;

              accept, now what I have done is created movieClips so I can use

              onPress, onRollOver, and OnRollOut

              then added textFields to the movie clips.

              What is happening (or failing to happen) is that the onPress handler is

              not recognizing items in a global array

               

              eval('listMCplay'+i).onPress = function():Void

                                                            {

                                                             //trackToLoad =

              playListPaths[i];

                                                             currentTrackIndex = i;

                                                              

              trace(playListPaths[currentTrackIndex].path)  // << fails: 'undefined'

                                                             //fscommand("alert",

              playList[i])

                                                             // call javascript

              alert(playList[i])

                                                            }

               

              Attached is portion present state of my code.

               

              • 4. Re: this.creatTextField() help
                Rothrock Level 5

                I can't read your code cause it is all full of non-breaking spaces code.

                 

                My guess is that you are trying to access the value of "i" when pressed, but the value of i when you assign the onPress handler isn't retained and there for the value isn't going to be retained properly when the actual event happens. So what you need to do is assign the movieclip a variable like myID that will retain the value of "i".

                 

                So some thing like this:

                 

                var home:MovieClip=this;

                 

                for (var i =0;i<playListPaths.length;i++){

                  var curPlay:MovieClip=home["listMCPlay"+i]

                  curplay.myID=i;

                  curPlay.onPress=handlePress

                }

                 

                function handlePress(){

                  var trackToLoad=playListPaths[this.myID]

                }

                • 5. Re: this.creatTextField() help
                  ASJoke Level 1

                   

                  Sorry about the code formatting. When the message is posted, the width

                  of the display

                  wraps the text shorter than the lines I used to write the message.

                   

                  I solved the problem. In the playListPlay object. I record the x left

                  and right corners

                  and the y top and bottom. Then when the onPress event occurs for the

                  button

                  the handler function loops through the playListPlay array and finds the

                  coordinate

                  set that encompasses  _xmouse and _ymouse position.

                   

                  But your approach looks much simpler. I actually had created an .id

                  item to save

                  the value of i but I don't have enough understanding of the use of the

                  keyword

                  this to figure out how to use it as you have.

                   

                  Thank you for your time and attention.

                  JK

                   

                  • 6. Re: this.creatTextField() help
                    ASJoke Level 1

                    I don't know where the nbsp;'s came from here. I got plenty of helpful advice, thanks.

                    I also thought it right to mention that the files I attached are Unix formatted text files.

                    So line breaks are line feed. If they are viewed on a Windows machine, the formatting

                    will be lost because Windows recognizes line feed-carrage return as line breaks.

                    (for anyone who might not know).

                     

                    Thank you again for time and attention

                    JK