14 Replies Latest reply on Mar 16, 2010 7:42 AM by adamgeework

    Can you use components in the Script area?

    adamgeework

      I really would like to implement the linkbutton in my functions.

        • 1. Re: Can you use components in the Script area?
          saisri2k2 Level 4

          You can use action script for this

           

           

          LinkButton bt = new LinkButton();

          bt.setStyle("icon",className);

           

          this.addChild(bt);

           

          or you want to access it?

          • 2. Re: Can you use components in the Script area?
            adamgeework Level 1

            thanks... setStyle chooses a css style i assume?

            • 3. Re: Can you use components in the Script area?
              adamgeework Level 1

              public function mainFunction():void{

               

               

               

                              var cache:int = 0;

               

                              while(myCanvas.rawChildren.numChildren >0){

               

                                  myCanvas.rawChildren.removeChildAt(0);

               

               

               

                              }

               

               

               

                              var myButton:LinkButton = new LinkButton();   //linkButton

               

               

                                  myButton.label = "heyhey"

                                                     myCanvas.addChild(myButton);

               

               

               

                              //text format for links

               

                                  var linkFormat:TextFormat = new TextFormat();

               

                                  linkFormat.font = "Verdana";

               

                                     linkFormat.color = 0x3391cd;

               

                                  linkFormat.size = 16;

               

               

               

                         

               

                                  //text format end

               

                             

               

                              var total_amt:Number = full_array.length;

               

                             

               

                              amt_cnt.start = 0;

               

                              amt_cnt.total = total_amt;

               

                              if(amt_cnt.total < 5){

               

                                  amt_cnt.end = amt_cnt.total;

               

                                 

               

                                 

               

                                 

               

                                  //set the text

               

                             

               

                                 

               

               

               


                                 
                                  var helpSprite:Sprite = new Sprite();
                                  var text_help:TextField = new TextField();
                                  text_help.defaultTextFormat = linkFormat;
                                  text_help.text = "Can't find your answer? Need more help?";
                                  text_help.selectable = false;
                                  text_help.x = 100;
                                  text_help.height = 20;
                                 
                                  text_help.mouseEnabled = false;
                                  text_help.width = text_help.textWidth+10;
                                 
                                 
                                 
                                 
                                  //end set text
                                 
                                      helpSprite.y = 200;
                                  helpSprite.buttonMode = true;
                                  helpSprite.addChild(text_help);
                                  myCanvas.rawChildren.addChild(helpSprite);
                                 
                                  helpSprite.addEventListener(MouseEvent.CLICK, moreHelp);
                                 
                this is a segment of my function where i think is the problem.

              I added the link button and myCanvas.addChild(myButton) but now when i run this function after the first attempt i get a "supplie index is out of bounds" error message. IT only occurs when the link button is there. Any ideas?

              • 4. Re: Can you use components in the Script area?
                AdrianWiecek Level 3

                Hi,

                 

                This error probably occurs when you are removing children from canvas. Try replacing your while block with something like that(it's written "on the fly" without compiler so errors can occur):

                 

                for(var i:int = 0 ; i < myCanvas.numChildren - 1 ; i++)

                {

                     myCanvas.removeChildAt(i);

                }

                 

                Regards,

                Adrian Wiecek

                • 5. Re: Can you use components in the Script area?
                  adamgeework Level 1

                  i think you meant something like that but reversed?:

                      for(var z:int = myCanvas.rawChildren.numChildren-1; z > 0; z--)

                   

                                  {
                                        trace(z);
                                           myCanvas.rawChildren.removeChildAt(z);

                   

                                  }

                   

                  still same problem.

                  It must be an issue with the rawChildren and the linkButton not using that method....

                  • 6. Re: Can you use components in the Script area?
                    AdrianWiecek Level 3

                    Yes that's my fault. Can you post error message from compiler? And can I ask, why are you removing children using myCanvas.rawChildren.removeChildAt(), not just myCanvas.removeChildAt() ?

                    • 7. Re: Can you use components in the Script area?
                      adamgeework Level 1

                      RangeError: Error #2006: The supplied index is out of bounds.
                          at flash.display::DisplayObjectContainer/addChildAt()
                          at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::$addChildAt()[C:\autobuild\3.2.0\frameworks\pr ojects\framework\src\mx\core\UIComponent.as:5083]
                          at mx.core::Container/addChildAt()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\c ore\Container.as:2215]
                          at mx.core::Container/addChild()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\cor e\Container.as:2140]
                          at helpdeskApp/mainFunction()[/Users/adamgee/Documents/Flex Builder 3/helpdeskApp/src/helpdeskApp.mxml:137]
                          at helpdeskApp/onResult()[/Users/adamgee/Documents/Flex Builder 3/helpdeskApp/src/helpdeskApp.mxml:113]

                       

                       

                       

                      I'm using rawChildren because my Sprites were using rawChildren.addChild... I dont really know why but sprites only appear if you do that. So the only way to remove these children is by adding the rawChildren.

                       

                      Now this linkButton is not added using rawChildren because im assuming it is some special flex class.

                      • 8. Re: Can you use components in the Script area?
                        AdrianWiecek Level 3

                        This type of error occurs while reparenting component without using removeChild() first. Are you sure that this LinkButton is newly created and has not been already a child of other container? You said that it happens after first call of the method so this can be the source of your problem.

                         

                        Regards,

                        Adrian Wiecek

                        • 9. Re: Can you use components in the Script area?
                          adamgeework Level 1

                          well i jsut used two while loops i had earlier

                           

                          one with rawChildren and one without.


                          Thanks for your help.  i could have sworn had errors with this code as well, but not right now.

                          • 10. Re: Can you use components in the Script area?
                            adamgeework Level 1

                            ok now in that same function i put the LinkButtons in a forloop()

                             

                            and i get ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

                             

                             

                             

                            I found this link http://play.blog2t.net/finding-the-missing-child/

                             

                            the while loops that delete the children should only run if there are children correct? Why would anything be trying to delete a child if it is not there?

                             

                            I take the while loops out and it doesnt give the error.

                             

                            Can someone explain this?

                            • 11. Re: Can you use components in the Script area?
                              Flex harUI Adobe Employee

                              What does the code look like now?

                              • 12. Re: Can you use components in the Script area?
                                adamgeework Level 1

                                public function mainFunction():void{

                                 

                                 

                                 

                                                var cache:int = 0;

                                 

                                 

                                 

                                            while(myCanvas.numChildren > 0){

                                 

                                 

                                 

                                                myCanvas.removeChildAt(0);

                                 

                                 

                                 

                                            }

                                 

                                            while(myCanvas.rawChildren.numChildren > 0){

                                 

                                 

                                 

                                                myCanvas.rawChildren.removeChildAt(0);

                                 

                                            }

                                 

                                           

                                 

                                           

                                 

                                                //text format for links

                                 

                                               

                                 

                                           

                                 

                                                    //text format end

                                 

                                               

                                 

                                           

                                 

                                               

                                 

                                                if(amt_cnt.count == 1){

                                 

                                                    amt_cnt.end = amt_cnt.endCache;

                                 

                                                    amt_cnt.start = amt_cnt.startCache;

                                 

                                                   

                                 

                                           

                                 

                                                   

                                 

                                                    //set the text

                                 

                                               

                                 

                                                    var myButton:LinkButton = new LinkButton();

                                 

                                                    myButton.label = "Can't find your answer? Need more help?";

                                 

                                                    myButton.x = 275;

                                 

                                                    myButton.y = 200;

                                 

                                                    myCanvas.addChild(myButton);

                                 

                                                    myButton.addEventListener(MouseEvent.CLICK, moreHelp);

                                 

                                                   

                                 

                                                }else{

                                 

                                                   

                                 

                                                    amt_cnt.end = amt_cnt.endCache;

                                 

                                                    amt_cnt.start = amt_cnt.startCache;

                                 

                                                   

                                 

                                                    var myButton1:LinkButton = new LinkButton();

                                 

                                                    myButton1.label = "Can't find your answer? There are more answers.";

                                 

                                                    myButton1.x = 275;

                                 

                                                    myButton1.y = 200;

                                 

                                                    myCanvas.addChild(myButton1);

                                 

                                                    myButton1.addEventListener(MouseEvent.CLICK, moreQuestions);

                                 

                                                   

                                 

                                               

                                 

                                                }

                                 

                                 

                                 

                                 

                                 

                                well it doesnt have to be in a forloop...

                                • 13. Re: Can you use components in the Script area?
                                  adamgeework Level 1

                                  and only myButton1 causes this issue.

                                  • 14. Re: Can you use components in the Script area?
                                    adamgeework Level 1

                                    i guess i'll use textfields.