Skip navigation
ic3man7019
Currently Being Moderated

How do you maintain data and create new textInput fields when destroying/creating new views?

Jun 8, 2013 9:13 PM

Tags: #flex_mobile

Basically, I need to know how to create another textInput field when I pass data from one view to the next, while saving the data that was passed to begin with.

I want the user to be able to enter text into a textInput field on the first view and see it on the next view, BUT I want the next view to save what the user entered, navigate back to the first view, then take another entry from the user and create another textInput field on the second view. It's like a memo pad app. The user enters a task on the first view, then he or she is able to see it on the second view. Then, the user should be able to navigate back to the first view and create another task that also goes to the second view, but does not replace the first task that was entered. My problem is creating new textInput fields as new data comes in to the second view. Any ideas? Perhaps textInput fields are not the visual components I should be using...

 
Replies
  • Currently Being Moderated
    Jun 10, 2013 6:06 AM   in reply to ic3man7019

    You need to check out the MVC pattern and use a model.

     

    A crude way to do what you want is to use a singleton object, accessible from anywhere, to exchange data between views.

     

    Google flex globals and singleton objects.

     

    http://stackoverflow.com/questions/9505141/how-does-one-declare-a-glob al-variable-in-actionscript

     

    This may help you, but it's really not the way to be building apps. You need to learn about MVC.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 10, 2013 8:53 AM   in reply to ic3man7019

    I usually use a singleton. It basically a class that only gets instantiated once and remains in memory. You access it by getting the instance and then getting or setting the variables you are storing.

     

    Below us an example of a Singleton called AppGlobals with some getter setters for a string named strTest.

     

    package

    {

              public class AppGlobals

              {

                        private static var _instance:AppGlobals;

                        public function AppGlobals(pvt:AppGlobalsPrivateClass)

                        {

                        }

                        public static function getInstance():AppGlobals

                        {

                                  if (AppGlobals._instance==null)

                                  {

                                            AppGlobals._instance=new AppGlobals(new AppGlobalsPrivateClass());

                                  }

                                  return AppGlobals._instance;

                        }

     

                        private var _strTest:String;

                        public function get strTest():String { return _value; }

                        public function set strTest()(value:String):void{_strTest=value;}

              }

    }

    class AppGlobalsPrivateClass{public function AppGlobalsPrivateClass(){}}

     

     

     

    To save a variable in some other class or view. First set a variable to the instance of the singleton.

     

    import AppGlobals;

    private var a:AppGlobals=AppGlobals.getInstance();

     

    Then in a function do somtheing like:

     

    a.strTest="This is setting the test variable."

    trace(a.strTest());

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 10, 2013 8:58 AM   in reply to JDeLuca9198
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2013 8:57 AM   in reply to ic3man7019

    Glad that was helpful. I just realized a typo.

     

    public function get strTest():String { return _value; }

     

    is supposed to be

     

    public function get strTest():String { return _strTest; }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points