开发者

Flex: create buttons dynamically and assign value from txt file

开发者 https://www.devze.com 2023-03-20 16:25 出处:网络
I made a basic text editor that lets users insert predefined strings into the document with button clicks. What I need to do now is let the user define their own buttons and string values.

I made a basic text editor that lets users insert predefined strings into the document with button clicks. What I need to do now is let the user define their own buttons and string values.

For example I have a button that inserts "Hello" into the text. The user may want to create a button that adds "Goodbye".

To accomplish this I figured I would create a .txt file called buttons.txt or something. i would readutfbytee, loop through it to create the buttons. problem is I 开发者_Python百科know what I want to do but not sure where to start. Can someone give me a kick start?


Please check the following code as the simple way to externalize your button settings:

 /*
    buttons.txt content sample:     
    Helo=Hello World&Test=Test Inserted   
   */

    protected function loadSettings():void
    {
      var varLoader:URLLoader = new URLLoader();
      varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
      varLoader.addEventListener(Event.COMPLETE, onSettingsLoaded);
      varLoader.load(new URLRequest("data/buttons.txt"));
    }

    protected function onSettingsLoaded(event:Event):void
     {
      var varLoader:URLLoader = URLLoader(event.target);
      var varButtons:URLVariables = varLoader.data;
      var buttons:Dictionary = new Dictionary();
      for(var label:String in varButtons{
        buttons[label]=varButtons[label].toString().split(",");
      }

      //use parsed buttons dictionary
    }


For starters you need to decide how you are going to store that data that the user enters.

A flex web app can't save any files to the server, so if you want to save this across multiple computers, you'll need a server to do the data saving / retrieval.

If you want to store the buttons just temporarily, and unique to one computer, you can stuff them into a SharedObject.

After you decide this, then you can get more specific on a question of how to do exactly what you're wanting.

0

精彩评论

暂无评论...
验证码 换一张
取 消