2 Replies Latest reply on Jul 29, 2008 8:26 PM by Newsgroup_User

    Text not initialized, even though Application.creationComplete...?

    iamoj
      (I know OOP from Java, but am somewhat new to ActionScript.)

      I have a MXML application with this attribute:
      <mx:Application ...creationComplete="myMethod(...)"...>

      In the Application, I have an <mx:Text> (which sits inside an <mx:VBox>, which is inside an <mx:ViewStack>, etc.).

      When myMethod(...) is called upon creationComplete, I cannot get the <mx:Text> by reference: it is null! The problem: the container VBox.initialized is false.

      If I wait a few seconds and click a button that calls myMethod(...), then the VBox has had time to initialize.

      I don't know if this is a bug -- it seems that creationComplete shouldn't be called until all children of Application have been initialized. Or perhaps Flex 3 uses "lazy initialization"? Anyway...

      MY PROBLEM: I want to delay execution of myMethod(...) until the VBox is initialized.

      How to do this? In Java, I would do something like, "while (myText.initialized == false) try {Thread.sleep(500);}..."

      Any ideas how to wait for (or force) full initialization?
        • 1. Re: Text not initialized, even though Application.creationComplete...?
          Level 7

          "iamoj" <webforumsuser@macromedia.com> wrote in message
          news:g6ok6k$ekg$1@forums.macromedia.com...
          > (I know OOP from Java, but am somewhat new to ActionScript.)
          >
          > I have a MXML application with this attribute:
          > <mx:Application ...creationComplete="myMethod(...)"...>
          >
          > In the Application, I have an <mx:Text> (which sits inside an <mx:VBox>,
          > which is inside an <mx:ViewStack>, etc.).
          >
          > When myMethod(...) is called upon creationComplete, I cannot get the
          > <mx:Text>
          > by reference: it is null! The problem: the container VBox.initialized is
          > false.
          >
          > If I wait a few seconds and click a button that calls myMethod(...), then
          > the
          > VBox has had time to initialize.
          >
          > I don't know if this is a bug -- it seems that creationComplete shouldn't
          > be
          > called until all children of Application have been initialized. Or perhaps
          > Flex
          > 3 uses "lazy initialization"? Anyway...
          >
          > MY PROBLEM: I want to delay execution of myMethod(...) until the VBox is
          > initialized.
          >
          > How to do this? In Java, I would do something like, "while
          > (myText.initialized
          > == false) try {Thread.sleep(500);}..."
          >
          > Any ideas how to wait for (or force) full initialization?
          >

          You could call the method on creationComplete of the VBox...

          Or, depending on what is going on, you may need to override commitProperties
          or updateDisplayList and call it in one of those places.

          HTH;

          Amy


          • 2. Re: Text not initialized, even though Application.creationComplete...?
            g-s-b Level 1
            Have you tried:

            <mx:VBox creationComplete="myMethod(...) " ... >
            ...
            </mx:VBox>

            There is not a 'sleep' exactly. But you could use a timer loop OR an onFrameEvent handler function.