6 Replies Latest reply on Oct 9, 2008 12:10 PM by Newsgroup_User

    Communicating between a class and mxml

    SiHoop Level 1
      I'm making the transition from using lots of code in my projects to writing classes and am attempting to convert some functions into a class. The code below is the core of a class that has a problem with the line:
      linkStack.selectedChild = teachers_module;

      linkStack is the id of a ViewStack in my mxml document, and admin_module and teachers_module are the ids of two component in that ViewStack.

      <comp:Admin id="admin_module" />
      <comp:Teachers id="teachers_module"/>
      I understand that the class is not communicating with the main file, but cannot figure out how to pass back the value to the main file. What should I do differently?
        • 1. Re: Communicating between a class and mxml
          Level 7

          "SiHoop" <webforumsuser@macromedia.com> wrote in message
          news:gcjloj$nqb$1@forums.macromedia.com...
          > I'm making the transition from using lots of code in my projects to
          > writing
          > classes and am attempting to convert some functions into a class. The code
          > below is the core of a class that has a problem with the line:
          > linkStack.selectedChild = teachers_module;

          I think this is a Q3
          http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf
          but you may also want to check Q5 as well.

          HTH;

          Amy


          • 2. Re: Communicating between a class and mxml
            SiHoop Level 1
            I solved the initial problem-- still learning to pass objects to the class! But now Flex is telling me that I have a null object reference which I'm almost certain is caused by the following line in my class:
            linkStack.selectedChild = admin_module;

            linkStack is the ViewStack which has been properly imported and declared in the class, but I think it's having trouble with admin_module which is the id of the component that I'm attempting to link to. I assume that it was able to 'see' the object when the code was in the function, but now it is probably undeclared and I'm not sure what to do about that. If that correct, how would I declare such a variable? The line of code below is from the original mxml file that I'm trying to connect to.

            <comp:Admin id="admin_module" />

            • 3. Re: Communicating between a class and mxml
              Gregory Lafrance Level 6
              By default, the children of the ViewStack will not be instantiated until they are first accessed. You can get around that by setting the ViewStack creationPolicy="all", but that can affect performance, depending on what the children contain.

              In the past Amy has commented on this same issue, on ways to solve the problem without resorting to creationPolicy="all". Maybe she will chime in.
              • 4. Re: Communicating between a class and mxml
                Level 7

                "Greg Lafrance" <webforumsuser@macromedia.com> wrote in message
                news:gckb2e$hsv$1@forums.macromedia.com...
                > By default, the children of the ViewStack will not be instantiated until
                > they
                > are first accessed. You can get around that by setting the ViewStack
                > creationPolicy="all", but that can affect performance, depending on what
                > the
                > children contain.
                >
                > In the past Amy has commented on this same issue, on ways to solve the
                > problem
                > without resorting to creationPolicy="all". Maybe she will chime in.

                That's Q5, as I said. But I think this is a Q3...A component is not in the
                same scope as its parent, so if you try to refer to myParent.myProperty,
                you're setting yourself up for disappointment.

                I think sometimes my replies don't show up on the forum (either that or
                people completely and totally ignore my advice for some reason LOL). But
                since I often see what looks like one side of a conversation on here, I
                think that the NNTP side and the forum side are incompletely connected.

                In case my older reply didn't come through, here is the address of the FAQ,
                and Q3 and Q5 are the ones you want to look at
                http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf


                • 5. Re: Communicating between a class and mxml
                  SiHoop Level 1
                  Hi Amy,
                  I thought I'd comment on your last post about people not following through with your feedback. I did read your FAQ, but being a novice found the problem solution difficult to understand. I find that the best way for me to learn is to deconstruct code. Very often, a logical, didactic explanation of how to solve a problem will not work as some of the steps in the solution are too difficult for me to understand. Once I know how to solve the problem, then I can understand the explanation!
                  Please do not take this as criticism, I'm only presenting a 'user' perspective and trying to explain why it may appear that your efforts are being ignored (which they are not). As always, many thanks for your help. I've learned a tremendous amount from you.
                  BTW, I solved the ViewStack problem by passing a value back from the class and using that in a conditional statement to pick my container.
                  • 6. Re: Communicating between a class and mxml
                    Level 7

                    "SiHoop" <webforumsuser@macromedia.com> wrote in message
                    news:gclgq3$7dp$1@forums.macromedia.com...
                    > Hi Amy,
                    > I thought I'd comment on your last post about people not following through
                    > with your feedback. I did read your FAQ, but being a novice found the
                    > problem
                    > solution difficult to understand. I find that the best way for me to learn
                    > is
                    > to deconstruct code. Very often, a logical, didactic explanation of how to
                    > solve a problem will not work as some of the steps in the solution are too
                    > difficult for me to understand. Once I know how to solve the problem, then
                    > I
                    > can understand the explanation!
                    > Please do not take this as criticism, I'm only presenting a 'user'
                    > perspective
                    > and trying to explain why it may appear that your efforts are being
                    > ignored
                    > (which they are not). As always, many thanks for your help. I've learned a
                    > tremendous amount from you.
                    > BTW, I solved the ViewStack problem by passing a value back from the class
                    > and
                    > using that in a conditional statement to pick my container.

                    I wasn't actually referring to this thread at all. I apologize if it seemed
                    that way.