7 Replies Latest reply on Mar 11, 2010 10:51 AM by Flex harUI

    adding sprites to the app

    adamgeework

      public function onResult(responds:Object):void{

       

       

       

                  var main_sprite:Sprite = new Sprite();

       

                      searchgrid.dataProvider = responds;

       

                      this.rawChildren.addChild(main_sprite);

       

                      for(var t:uint = 0; t<responds.length; t++){

       

                          var txt:Text = new Text();

       

                          txt.text = responds[t].question;

       

                          txt.y = t*20;

       

                          main_sprite.addChild(txt);

       

                        

       

                        

       

                      }

       

                

       

                

       

              }

       

       

      Is there something wrong im doing here?

       

      I just want my txt to be placed into main_sprite so I can clear all of mainsprite when this function runs again.

        • 1. Re: adding sprites to the app
          Flex harUI Adobe Employee

          Flex components must be parented by other Flex components.  Sprite is a

          low-level Flash Player "component".  Use UIComponent or a Container instead.

          1 person found this helpful
          • 2. Re: adding sprites to the app
            adamgeework Level 1

            so i've changed it to

             

            public function onResult(responds:Object):void{
                           
                        var main_sprite:UIComponent = new UIComponent();
                            searchgrid.dataProvider = responds;
                            this.addChild(main_sprite);
                            for(var t:uint = 0; t<responds.length; t++){
                                var txt:Text = new Text();
                                txt.text = responds[t].question;
                                txt.y = t*20;
                                main_sprite.addChild(txt);
                               
                               
                            }
                       
                       
                           
                           
                        }

             

            but still nothing. Keep in mind just addChild(txt); to the "main" stage works.

            • 3. Re: adding sprites to the app
              Flex harUI Adobe Employee

              Like I said, UIComponent has no default behavoir.  Try using Canvas instead.

              • 4. Re: adding sprites to the app
                adamgeework Level 1

                i have this now:

                 

                            for(var t:uint = 0; t<responds.length; t++){
                                    var mc:Sprite = new Sprite();
                                    var txt:Text = new Text();
                                    var ans:Text = new Text();
                                    txt.text = responds[t].question;
                                    ans.text = responds[t].answer;
                                   
                                    mc.addChild(txt);
                                    mc.addChild(ans);
                                    mc.y = t*60;
                                    myCanvas.rawChildren.addChild(mc);
                                   
                                }

                 

                 

                myCanvas being a mx:Canvas and still nothing.

                 

                I can add the textfields directly to the canvas, but not to sprite then canvas..

                • 5. Re: adding sprites to the app
                  Flex harUI Adobe Employee

                  Sprite is not a Flex component so it can't be in the mix.  Use UIComponent

                  instead of Sprite or another Canvas instead of Sprite, or make a new

                  component based on UIComponent.

                  • 6. Re: adding sprites to the app
                    adamgeework Level 1

                        public function onResult(responds:Object):void{
                                   
                                   
                                     var ui:UIComponent = new UIComponent();
                                  
                                    for(var t:uint = 0; t<responds.length; t++){
                                       
                                        var txt:Text = new Text();
                                        var ans:Text = new Text();
                                        txt.text = responds[t].question;
                                        ans.text = responds[t].answer;
                                        txt.y = t*70;
                                        ans.y = txt.y + 20;
                                       
                                       
                                        ui.addChild(txt);
                                        ui.addChild(ans);
                                       
                                       
                                       
                                    }
                               
                                myCanvas.addChild(ui);
                                   
                                   
                                }

                     

                    Something like this? sorry I dont get it because it's not working.

                     

                     

                     

                    Maybe i'll just tell you want I want to do, because there may be an existing component i can just modify.

                     

                    I want my "questions" from my database to be displayed, and when a question is clicked the question and answer will be displayed above the list.

                    I dont want it to look like some datagrid or anything. It needs to be borderless... maybe look like something that was built in flash.

                    • 7. Re: adding sprites to the app
                      Flex harUI Adobe Employee

                      Try using another Canvas instead of UICOmponent