7 Replies Latest reply on Jan 18, 2009 9:12 AM by w_danilo

    Loader -addChild problem.

    w_danilo
      Hi, I've recently written a part of a small application, but I can not pass throught an error - I've asked about it in another forums, but nobody knows the answer so the probelm is that:
      1) I've created a Loader; it loads swf file inside.
      2) When I apply to complete handler of theseloader a function, which adds this loader to the stage (methods: rawchildren.addChild(...) or It creates new UIComponent, which is added to the stage and inside this component the loader) - everything is ok - I see the result on the sage, but:
      3) When complete handler makes nothing and i apply these loader to the stage by button-function ... nothing happens? - I can't see anything new on the stage. Why? (quick example attached below).
      I reallyplease about your help! :):):)

      (complete flex project: http://danilo.ocom.pl/arch.rar )

      (FLEX) WHEN YOU CREATE PROJECT AND USE CODE1 IT WORKS, BUT WITH CODE2 AFTER PRESSING BUTTON NOTHING HAPPENS. WHY?
        • 1. Re: Loader -addChild problem.
          ntsiii Level 3
          First, why are you using rawChildren? That is preventing flex from laying out the children properly.

          Perhaps Code1 works because there are
          no children on the DisplayList, but Code2 has a button which does not play well with anything on the rawChildren list.
          • 2. Re: Loader -addChild problem.
            ntsiii Level 3
            Also, why are you using Loader and not SWFLoader?
            • 3. Re: Loader -addChild problem.
              w_danilo Level 1
              Hi, thanks for your answers, but, when I use addChild - normal method it throws an error that loader in not an UIComponent. Of course when I create new UIComponent, then add loader as a child to it and then add this ui component to the stage - the bahaviour is the same. code1 works and code2 doesn't.
              And I have additional question - why schouldn't I use Loader to load swf - manual says,that we can use loader to load images etc and swf ... ?
              "The Loader class is used to load SWF files or image (JPG, PNG, or GIF) files."
              • 4. Loader -addChild problem.
                w_danilo Level 1
                Additional when I use swfLoader - the error still is :( (code 5). - this doesn't simply work. When I press button, nothing happens :(
                THESE CODES DON'T WORK: (here I use UIComponent, so everything schould be ok, but it's not :(
                • 5. Re: Loader -addChild problem.
                  Level 7

                  "w_danilo" <webforumsuser@macromedia.com> wrote in message
                  news:gkvihj$5ld$1@forums.macromedia.com...
                  > Hi, thanks for your answers, but, when I use addChild - normal method it
                  > throws
                  > an error that loader in not an UIComponent.

                  I think that error is pretty informative, but it could be more specific.
                  What it means is that you're trying to add a component that doesn't
                  implement IUIComponent to a component that is set up to only take components
                  that implement that interface as children, most likely a Container subclass.

                  > Of course when I create new
                  > UIComponent, then add loader as a child to it and then add this ui
                  > component to
                  > the stage - the bahaviour is the same. code1 works and code2 doesn't.

                  It seems like a race condition...something you're trying to do is not ready
                  when you start the chain of events at initialize, but it is when you can see
                  the button on the screen, after creationComplete.

                  > And I have additional question - why schouldn't I use Loader to load swf -
                  > manual says,that we can use loader to load images etc and swf ... ?
                  > "The Loader class is used to load SWF files or image (JPG, PNG, or GIF)
                  > files."

                  Because swfLoader already implements IUIComponent...?

                  -Amy


                  • 6. Re: Loader -addChild problem.
                    ntsiii Level 3
                    Do not use rawChildren.

                    There are rules for what can contain what:
                    1. navigator children must be containers
                    2. Container children must be IUIComponents
                    3. UIComponent children can be anything

                    Loader is not a UIComponent, so you can't add it to an Application. SWFLoader *is* a UIComponent, so you can use Application.addChild

                    Code5 is close.

                    You may have a tming issue, though I am not sure why the behaviors are different. Try rearranging the order of the calls. Can you addChild the loader in the completion handler?

                    Maybe try callLater to set the content.visible.

                    Note that "content" is not necessarily ready to be accessed in the SWFLoader Complete handler. You may need to listen for the applicationComplete event.

                    Here is a full example of using SWFLoader that might help:
                    http://www.cflex.net/showfiledetails.cfm?ChannelID=1&Object=File&objectID=690
                    • 7. Loader -addChild problem.
                      w_danilo Level 1
                      Amy Blankenship :
                      Thank You for reply. I understeand everything, you've written, but this example, I've posted behaves not exactly as you mean. So CODE1 works (and this code addChild to the stage after loading is completed) and CODE2 doesn't work - BUT IT DOES THE SAME THINGS AS CODE1 - i press the button (which add loader to the stage) "a lot of time after" loading is completed (as trace method tells).
                      f.e - i start application - it traces (loading in progres.... loaded complete - then I wait a minute or tw, press the button and nothing happens, but when I add the same function to complete handler as to the button it works. (additional in both ways everything happens when the application is already initialized)

                      ntsiii:
                      Thank You for your answer. Ok I won't use rawChildren any more ;] I've seen that article, you've posted, but I think it's saying nothing about addingloaded object to the stage (yes It says about progress methods etc, but I write here really simple codes because they are clean and easy to follow - additional I wont to write the all code for this loader in AS3 :) )
                      For some reasons I can't addChild the loader in the completion handler in my app. But, when I test this "CODE 5" application it traces "complete" when loading is completed (i get traced):
                      "
                      [SWF] lt.swf - 1 024 076 bytes after decompression
                      [SWF] test3.swf - 352 342 bytes after decompression
                      complete
                      c1
                      "
                      and I press the button really a lot of time after it's loaded. What is very interesting, that when I addChild the loader in the completion handler - it works (but in this application I won't do that)

                      AND when I addChild by button and then when I call load again (manual says that loading again is reloading) - after reload is complete this object appears on the stage (without addChild)! :(
                      (This happens with SWFLoader and Loader class too).

                      So concluding I really need to load this SWF and add it by pressing the button to the stage (not reload it) and I write everything in AS3. How schould this code look like? :(