14 Replies Latest reply on Jan 5, 2009 9:08 AM by Newsgroup_User

    Add Child Element Appears Twice on Different Panels?

    alice_data
      Hi,

      I am guessing that I must have done something wrong here. I have two panels here that I have used a large amount of Actionscript draw a diagram, and when the users finish making the selections, it should bring users the result.

      I have no problems with the result display of the first panel, except that when the result changes to a different state, the added child I attempt to add only to the second panel also gets displayed on the first panel.

      I have attached the entire code below, and I hope that someone on the list could help me figure out what the problem is here.

      Thanks in advance.

      Alice
        • 1. Re: Add Child Element Appears Twice on Different Panels?
          ntsiii Level 3
          I can't follow what your are saying or trying to do. Pull all of the irrelevant code out of the example to start with.

          Unrelated and unsolicited advice: set resultFormat="e4x", and use result and fault handlers.

          Tracy
          • 2. Re: Add Child Element Appears Twice on Different Panels?
            alice_data Level 1
            Hi, Tracy:

            Sorry for providing such a confusing example. Here is something that is what I am thinking of:
            When I execute the code, I get this error:

            ReferenceError: Error #1069: Property text not found on test2 and there is no default value.
            at mx.states::SetProperty/apply()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\states\S etProperty.as:205]
            at mx.core::UIComponent/applyState()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\ UIComponent.as:7199]
            at mx.core::UIComponent/commitCurrentState()[E:\dev\3.0.x\frameworks\projects\framework\src\ mx\core\UIComponent.as:7019]
            at mx.core::UIComponent/setCurrentState()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\ core\UIComponent.as:6948]
            at mx.core::UIComponent/set currentState()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\UIComponent.as:4260 ]
            at test2/changeState()[C:\Documents and Settings\Alice.Wei\My Documents\Flex Builder 3\intake_optimization\src\test2.mxml:34]
            at test2/__state_click()[C:\Documents and Settings\Alice.Wei\My Documents\Flex Builder 3\intake_optimization\src\test2.mxml:61]

            Could this big a Flash Player bug issue?

            Thanks for your help.

            Alice
            • 3. Re: Add Child Element Appears Twice on Different Panels?
              Level 7

              "alice_data" <webforumsuser@macromedia.com> wrote in message
              news:gjnsli$fi4$1@forums.macromedia.com...
              > Hi, Tracy:
              >
              > Sorry for providing such a confusing example. Here is something that is
              > what
              > I am thinking of:
              > When I execute the code, I get this error:
              >
              > ReferenceError: Error #1069: Property text not found on test2 and there is
              > no
              > default value.

              There doesn't seem to be a test2 that I could find in the code you
              provided...maybe that's the problem. You're trying to set something on an
              object that doesn't exist?


              • 4. Re: Add Child Element Appears Twice on Different Panels?
                alice_data Level 1
                HI, Amy:

                The name of the file is test2.mxml. Does this mean that I cannot have that?

                Alice
                • 5. Re: Add Child Element Appears Twice on Different Panels?
                  Level 7

                  "alice_data" <webforumsuser@macromedia.com> wrote in message
                  news:gjp1m7$2lm$1@forums.macromedia.com...
                  > HI, Amy:
                  >
                  > The name of the file is test2.mxml. Does this mean that I cannot have
                  > that?

                  No, but that was what was being referenced in your error, and so the first
                  thing to do to track it down is to figure out what it is. The next thing to
                  do is to figure out where line 61 is.


                  • 6. Re: Add Child Element Appears Twice on Different Panels?
                    alice_data Level 1
                    Hi,

                    I have added the import mx.controls.Label in my code to take away the original errors, instead of having the text constantly changing their properties. Looks like that I no longer see the error like I did before about the reference errors.

                    However, now I am back to seeing the same mx:Label text displaying when I change the state when I click back and forth between the two tabs, when I would like to see the text show only on the second tab. (Line 9~11)

                    Attached is the code, and thanks again for those who may help out.
                    • 7. Re: Add Child Element Appears Twice on Different Panels?
                      Level 7

                      "alice_data" <webforumsuser@macromedia.com> wrote in message
                      news:gjqm02$89p$1@forums.macromedia.com...
                      > Hi,
                      >
                      > I have added the import mx.controls.Label in my code to take away the
                      > original
                      > errors, instead of having the text constantly changing their properties.
                      > Looks
                      > like that I no longer see the error like I did before about the reference
                      > errors.
                      >
                      > However, now I am back to seeing the same mx:Label text displaying when I
                      > change the state when I click back and forth between the two tabs, when I
                      > would
                      > like to see the text show only on the second tab. (Line 9~11)

                      Honestly, do you really expect me to count down lines to find the code?

                      Alice, I have every sympathy, but it seems like you take the people who are
                      trying to help you completely for granted and you don't do anything to make
                      it easy for them to find the information in your code necessary to help you.
                      Try providing the offending label's id or text or event provide an inline
                      comment that says ^^this is the problem label.

                      -Amy


                      • 8. Re: Add Child Element Appears Twice on Different Panels?
                        alice_data Level 1
                        Hi, Amy:

                        Sorry, to answer your question, I am providing the markup in comments to show the problem of the code as shown below. I hope this will provide some signification for you to point out my problem this time.

                        Sorry about that. Thanks for helping me again.

                        Alice
                        • 9. Re: Add Child Element Appears Twice on Different Panels?
                          Level 7

                          "alice_data" <webforumsuser@macromedia.com> wrote in message
                          news:gjrn6n$k6t$1@forums.macromedia.com...
                          > Hi, Amy:
                          >
                          > Sorry, to answer your question, I am providing the markup in comments to
                          > show the problem of the code as shown below. I hope this will provide some
                          > signification for you to point out my problem this time.
                          >
                          > Sorry about that. Thanks for helping me again.

                          Could I get a copy of your ShapesFactory class? I can't see the problem
                          without running the file, and I can't run the file without that.


                          • 10. Re: Add Child Element Appears Twice on Different Panels?
                            alice_data Level 1
                            Hi, Amy:

                            Thanks for helping me figuring this out. The attached is the code from my ShapesFactory.as
                            What I have noticed is that if I shift around my rectangle, if I shift my mx:AddChild element to

                            <mx:AddChild relativeTo="{myCanvas4}" position="lastChild">
                            <mx:Label text="The answer to 5*4 is {total_incidence}" id="text6" x="40.9" y="9.95" fontWeight="bold" fontSize="12"/>
                            </mx:AddChild>

                            The text does show properly on the right tab, but if I shift around the "rectangle," I do have the text hidden behind the rectangle.

                            Thanks again for your help.

                            Alice
                            • 11. Re: Add Child Element Appears Twice on Different Panels?
                              Level 7

                              "alice_data" <webforumsuser@macromedia.com> wrote in message
                              news:gjt62s$k53$1@forums.macromedia.com...
                              > Hi, Amy:
                              >
                              > Thanks for helping me figuring this out. The attached is the code from
                              > my
                              > ShapesFactory.as
                              > What I have noticed is that if I shift around my rectangle, if I shift
                              > my
                              > mx:AddChild element to
                              >
                              > <mx:AddChild relativeTo="{myCanvas4}" position="lastChild">
                              > <mx:Label text="The answer to 5*4 is {total_incidence}"
                              > id="text6" x="40.9" y="9.95" fontWeight="bold" fontSize="12"/>
                              > </mx:AddChild>
                              >
                              > The text does show properly on the right tab, but if I shift around the
                              > "rectangle," I do have the text hidden behind the rectangle.

                              Could you step back a bit and state what it is you'd like to see with this
                              thing?


                              • 12. Re: Add Child Element Appears Twice on Different Panels?
                                Level 7

                                "alice_data" <webforumsuser@macromedia.com> wrote in message
                                news:gjt62s$k53$1@forums.macromedia.com...
                                > Hi, Amy:
                                >
                                > Thanks for helping me figuring this out. The attached is the code from
                                > my
                                > ShapesFactory.as
                                > What I have noticed is that if I shift around my rectangle, if I shift
                                > my
                                > mx:AddChild element to
                                >
                                > <mx:AddChild relativeTo="{myCanvas4}" position="lastChild">
                                > <mx:Label text="The answer to 5*4 is {total_incidence}"
                                > id="text6" x="40.9" y="9.95" fontWeight="bold" fontSize="12"/>
                                > </mx:AddChild>
                                >
                                > The text does show properly on the right tab, but if I shift around the
                                > "rectangle," I do have the text hidden behind the rectangle.
                                >
                                > Thanks again for your help.
                                >
                                > Alice
                                >
                                > // ActionScript file
                                >
                                > package {
                                >
                                > import flash.display.*;
                                >
                                > import mx.core.UIComponent;
                                >
                                > public class ShapesFactory extends Sprite
                                > {
                                > //some initial values
                                >
                                > public function Rectangle(x:int, y:int, width:int, height:int,
                                > color:uint):UIComponent
                                > {
                                > var rect:UIComponent=new UIComponent();
                                > rect.graphics.lineStyle(1);
                                > rect.graphics.beginFill(color,2);
                                > rect.graphics.drawRect(x,y,width,height);
                                > rect.graphics.endFill();
                                > return rect;
                                > }
                                >
                                > }//class
                                > }//package

                                It looks like your original problem is caused because for some reason it
                                can't add the label relative to the canvas, and so it is defaulting to being
                                relative to the application. This is probably lucky, because if it were
                                relative to the canvas it would be below the panel.


                                • 13. Re: Add Child Element Appears Twice on Different Panels?
                                  Level 7

                                  "alice_data" <webforumsuser@macromedia.com> wrote in message
                                  news:gjt62s$k53$1@forums.macromedia.com...
                                  > Hi, Amy:
                                  >
                                  > Thanks for helping me figuring this out. The attached is the code from
                                  > my
                                  > ShapesFactory.as
                                  > What I have noticed is that if I shift around my rectangle, if I shift
                                  > my
                                  > mx:AddChild element to
                                  >
                                  > <mx:AddChild relativeTo="{myCanvas4}" position="lastChild">
                                  > <mx:Label text="The answer to 5*4 is {total_incidence}"
                                  > id="text6" x="40.9" y="9.95" fontWeight="bold" fontSize="12"/>
                                  > </mx:AddChild>
                                  >
                                  > The text does show properly on the right tab, but if I shift around the
                                  > "rectangle," I do have the text hidden behind the rectangle.
                                  >
                                  > Thanks again for your help.
                                  >
                                  > Alice
                                  >
                                  > // ActionScript file
                                  >
                                  > package {
                                  >
                                  > import flash.display.*;
                                  >
                                  > import mx.core.UIComponent;
                                  >
                                  > public class ShapesFactory extends Sprite
                                  > {
                                  > //some initial values
                                  >
                                  > public function Rectangle(x:int, y:int, width:int, height:int,
                                  > color:uint):UIComponent
                                  > {
                                  > var rect:UIComponent=new UIComponent();
                                  > rect.graphics.lineStyle(1);
                                  > rect.graphics.beginFill(color,2);
                                  > rect.graphics.drawRect(x,y,width,height);
                                  > rect.graphics.endFill();
                                  > return rect;
                                  > }
                                  >
                                  > }//class
                                  > }//package

                                  OK, here's what's happening...myCanvas2 doesn't exist yet until the user
                                  clicks on the second tab, so the application can't create anything relative
                                  to it. Since this is the case, it defaults to adding it to the entire
                                  application. If you click the second tab first, everything works as
                                  expected. Gimme a second, and I'll have you an example file together.


                                  • 14. Re: Add Child Element Appears Twice on Different Panels?
                                    Level 7

                                    "alice_data" <webforumsuser@macromedia.com> wrote in message
                                    news:gjt62s$k53$1@forums.macromedia.com...
                                    > Hi, Amy:
                                    >
                                    > Thanks for helping me figuring this out. The attached is the code from
                                    > my
                                    > ShapesFactory.as
                                    > What I have noticed is that if I shift around my rectangle, if I shift
                                    > my
                                    > mx:AddChild element to
                                    >
                                    > <mx:AddChild relativeTo="{myCanvas4}" position="lastChild">
                                    > <mx:Label text="The answer to 5*4 is {total_incidence}"
                                    > id="text6" x="40.9" y="9.95" fontWeight="bold" fontSize="12"/>
                                    > </mx:AddChild>
                                    >
                                    > The text does show properly on the right tab, but if I shift around the
                                    > "rectangle," I do have the text hidden behind the rectangle.
                                    >
                                    > Thanks again for your help.
                                    >
                                    > Alice
                                    >
                                    > // ActionScript file
                                    >
                                    > package {
                                    >
                                    > import flash.display.*;
                                    >
                                    > import mx.core.UIComponent;
                                    >
                                    > public class ShapesFactory extends Sprite
                                    > {
                                    > //some initial values
                                    >
                                    > public function Rectangle(x:int, y:int, width:int, height:int,
                                    > color:uint):UIComponent
                                    > {
                                    > var rect:UIComponent=new UIComponent();
                                    > rect.graphics.lineStyle(1);
                                    > rect.graphics.beginFill(color,2);
                                    > rect.graphics.drawRect(x,y,width,height);
                                    > rect.graphics.endFill();
                                    > return rect;
                                    > }
                                    >
                                    > }//class
                                    > }//package

                                    http://www.magnoliamultimedia.com/flex%5Fexamples/Alice/#

                                    Also note that I slimmed down your ShapesFactory by making it extend Object.
                                    It doesn't need to extend Sprite.

                                    Also note that with the way you're using it, I would probably make it static
                                    and would not instantiate it. Instead, I'd call the static methods right
                                    from the class:

                                    package {

                                    import flash.display.Graphics;

                                    import mx.core.UIComponent;

                                    public class ShapesFactory
                                    {
                                    //some initial values

                                    public static function Rectangle(x:int, y:int, width:int, height:int,
                                    color:uint):UIComponent
                                    {
                                    var rect:UIComponent=new UIComponent();
                                    rect.graphics.lineStyle(1);
                                    rect.graphics.beginFill(color,2);
                                    rect.graphics.drawRect(x,y,width,height);
                                    rect.graphics.endFill();
                                    return rect;
                                    }

                                    }//class
                                    }//package

                                    Then use it like this:

                                    //don't put extra blank space in the UIComponent instead of positioning it
                                    myUIComponent = ShapesFactory.Rectangle(0, 0, 100, 30);
                                    //position it here
                                    myUIComponent.move(100, 100);

                                    Also note that properties and methods of classes, by convention, usually
                                    start with lowercase letters, so you should consider renaming the method
                                    rectangle instead of Rectangle. By the same token, you shouls consider
                                    renaming the Result state to result.

                                    HTH;

                                    Amy