4 Replies Latest reply on May 5, 2010 1:22 AM by Live today

    Facing problem to call a variable from anothe MXML Component.

    Live today Level 1

      How to access a variable declared in a function as "public" of an MXML Component, from another function of a deifferent MXML component. If the other MXML is declared as application I can access the canvas & BorderContaier. But If I declare as component instead of application it is not working in Flash Builder 4. Any solution?

        • 1. Re: Facing problem to call a variable from anothe MXML Component.
          SpaghettiCoder Level 3

          After a function finishes the variables declared in it, does not exist.

           

          You will need to

           

          1. Make the variable public.

          2. Have the variable declared outside of the function.

          • 2. Re: Facing problem to call a variable from anothe MXML Component.
            Live today Level 1

            I actually define the variable as "public", and also declared that before I start my function.

             

            But still the control is not able to fine the veritable from an MXML Component, as I declared that in an different MXMl Component.

            • 3. Re: Facing problem to call a variable from anothe MXML Component.
              SpaghettiCoder Level 3

              I see, when I read your post it looked like you were trying to access a variable you defined in a function.  In any case, have you given the component an ID? If you gave that component an ID you should be able to do instanceName.variableName to access the public variable.

              • 4. Re: Facing problem to call a variable from anothe MXML Component.
                Live today Level 1

                I have created two MXMl components in a single project. The main MXMl application is on default package and I put the two components on different package.

                 

                Now the two components alfa.mxml and bita.mxml are on package extra.I have declared the variable in alfa.mxml like

                 

                public var vid:Video;

                 

                and use this variable in the same mxml file like:

                 

                var vidHolder:UIComponent = new UIComponent();
                                    this.vid = new Video(camera.width, camera.height);
                                    vid.attachCamera(camera);
                                    vidHolder.addChild(vid);

                 

                 

                Now I have a function on bita.mxml named click.I tried to call the variable vid from this function like:

                 

                     private var card:alfa=new alfa();


                     public function click(): void{


                         var snapDt:BitmapData = new BitmapData(card.vid.width, card.vid.height);
                              

                                snapshotData.draw(card.video);

                                var scaleF:Number = this.pic.width/card.vid.width;


                }

                 

                Here I try with debug and alert, but I saw that the control is unable to call/trace the variable vid.

                 

                 

                In this same code I am facing another problem like:

                 

                I declared two canvases in this two mxml component.

                 

                for alfa.mxml


                <mx:Canvas id="wc" x="0" y="0">
                        </mx:Canvas>

                 

                and for bita.mxml

                 

                <mx:Canvas id="pic" width="75" left="10" top="10" borderStyle="none" borderColor="#000000">
                            </mx:Canvas>

                 

                Now, with wc I tried to view through webcam. Then, when I capture the image I tried to view that with pic.

                 

                The problem is that the control is able to find wc, and it works perfect but cannot find pic.

                 

                Can you plese resolve this problem too????

                .