[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

Restrict Textinput

Is it possible to do a global restrict on all textinput

something simular to a global style except i want  to restrict all textinputs i have, a lot, to all allow the same set of keys
1 Solution
whell, there is no global way of doing this. But there is a way to do this in a recursive loop. You loop through all instances on the stage/root, and then check if the instance is a textfield. Now you can set the text restriction on this textfield (even without instance names). With this loop even deeply nested textfields are restricted.

I have tested this script on textfields nested 3 levels deep, and it worked.

Hope this works for you.


restrict = function(objField){
	for(i in objField){
		if(objField[i] instanceof TextField)objField[i].restrict = "0-9"; // restricts to numbers
		if(objField[i] instanceof MovieClip)restrict(objField[i]);

Open in new window

jockmahon01Author Commented:
kewl that pretty good, cheers i dont use the timeline all my forms are movieclips in the lib but im sure i can use the instanceof, i had taught of the same thin but was using typeof and was only returning "movieClip"

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now