Restrict Textinput

Posted on 2008-11-14
Last Modified: 2012-06-27
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
Question by:jockmahon01
    LVL 8

    Accepted 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


    Author Comment

    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"

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
    The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
    The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
    The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now