Skip to main content
January 1, 2010
Answered

this.creatTextField() help

  • January 1, 2010
  • 1 reply
  • 649 views

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 = new Object();
              playListInfo.name = "INFO"+i;
              // x, y, width, height
              this.createTextField(playListInfo.name, this.getNextHighestDepth(), 0, 0, 0, 0) // <<--
              playListInfo.name._x = origin_x // <<-- since --.name is a string, I don't think this is working
              playListInfo.name._y = origin_y*(i+1)
              playListInfo.name._width = baseWdth
              playListInfo.name._height = baseHght
              playListInfo.name.text = "Info";
              playListInfo.name.setTextFormat(playListInfoForm);
              playListInfo.name.onPress = function()
                                             {
                                              var target = playListPaths;
                                              fscommand("alert", playList)
                                              // call javascript alert(playList)
                                             }
              playListInfo.name.onRollOver = function()
                                                 {
                                                  // change text color
                                                 }
              playListInfo.name.onRollOut = function()
                                                 {
                                                  // change text color to original
                                                 }

// similar code for two more textFields in each row

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

//strOut += playListInfo.name+" : "+playListPlay.name+" : "+playListTitle.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

This topic has been closed for replies.
Correct answer Rothrock

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;

currentTrackIndex = i;

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

//fscommand("alert",

playList)

// call javascript

alert(playList)

}

Attached is portion present state of my code.


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]

}

1 reply

January 1, 2010

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

so the way it goes is:  eval(playListInfo.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

Inspiring
January 1, 2010

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.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.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.

January 2, 2010

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;

currentTrackIndex = i;

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

//fscommand("alert",

playList)

// call javascript

alert(playList)

}

Attached is portion present state of my code.