11 Replies Latest reply on Feb 20, 2008 2:54 PM by jfillman

    Create text box?

    jefflemon Level 1
      How can I create a text box in AS3 that displays when a function is called?

      Thanks
        • 1. Re: Create text box?
          Gregory Lafrance Level 6
          What kind of a "text box"? There is the TextField and TextInput controls, and also the Text control and Label controls. Maybe you mean an Alert message box? In that case mx.controls.Alert.show("Here is my fancy alert!!!", "Alert Title Text");
          • 2. Re: Create text box?
            jfillman Level 1
            Use addItem to add it to a container or the application:

            private function addTextBox():void{
            var myTextBox:Text = new Text;
            myTextBox.width = 50;
            myTextBox.text = "Something";
            myContainer.addItem(myTextBox);
            }
            • 3. Re: Create text box?
              jefflemon Level 1
              I got rid of private becuase it said something about being in a class...

              function addTextBox():void{
              var myTextBox:Text = new Text;
              myTextBox.width = 50;
              myTextBox.text = "Something";
              myContainer.addItem(myTextBox);
              }

              now it says:
              call to a possibly undefined method addItem through a reference with a static type mx:containers.Canvas

              Whats going wrong..?

              Thanks
              • 4. Re: Create text box?
                jfillman Level 1
                Based on the error, I'm guessing that you didn't name your Canvas container "myContainer", or you don't have a container to add this item to. Keep in mind, we don't know all your code, so what is posted is generalized. Unless you post specific code, you have to modify these posts to work with the naming conventions and named items in your code.
                • 5. Re: Create text box?
                  Gregory Lafrance Level 6
                  If the code is in an ActionScript class that does not extend UIComponent I think this can occur as well.
                  • 6. Re: Create text box?
                    jefflemon Level 1
                    Here is my code:

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">


                    <mx:RemoteObject id="myservice" showBusyCursor="true" source="getmatt" destination="amfphp">
                    <mx:method name="getmatt1" result="resultHandler(event)" />
                    </mx:RemoteObject>



                    <mx:Script>
                    <![CDATA[
                    import mx.controls.Text;

                    import mx.managers.CursorManager;
                    import mx.rpc.events.ResultEvent;
                    import mx.rpc.events.FaultEvent;
                    import flash.display.Sprite;
                    import flash.text.TextField;
                    import flash.text.TextFieldAutoSize;

                    import mx.collections.ArrayCollection;



                    private function resultHandler(evt:ResultEvent):void
                    {


                    function addTextBox():void{
                    var myTextBox:Text = new Text;
                    myTextBox.width = 50;
                    myTextBox.text = "Something";
                    myContainer.addItem(myTextBox);
                    }


                    }


                    ]]>
                    </mx:Script>






                    <mx:Button x="183" y="192" label="Submit" width="79" click="myservice.getOperation('getmatt1').send();" id="button1"/>

                    <mx:Canvas x="62" y="222" width="200" height="200" id="myContainer">
                    </mx:Canvas>


                    </mx:Application>


                    I named teh canvas container mycontainer but still no luck, all that i shappening with the code is that when the button is pressed and a result returned it will create a text box

                    I still get the error:

                    call to a possibly undefined method addItem through a reference with a static type mx:containers.Canvas

                    Thanks for all ur help
                    • 7. Re: Create text box?
                      jfillman Level 1
                      This should fix it:
                      myContainer.addChild(myTextBox);

                      instead of addItem();
                      • 8. Re: Create text box?
                        jefflemon Level 1
                        Thanks, that did it...

                        I was just wondering how I would add an image, would it be in the same manner?
                        • 9. Re: Create text box?
                          jfillman Level 1
                          Same process:

                          1) Create the variable
                          2) Set the properties (height, width, source, etc).
                          3) Add it to the container
                          • 10. Re: Create text box?
                            jefflemon Level 1
                            cool, i tried this but it didnt seem to work:

                            function addImage():void{
                            var myImage = new Image;
                            myImage.Source = "images/pic.jpg";
                            myContainer.addItem(myImage);
                            }
                            • 11. Re: Create text box?
                              jfillman Level 1
                              Watch your syntax:

                              function addImage():void{
                              var myImage:Image = new Image;
                              myImage.source = "images/pic.jpg";
                              myContainer.addChild(myImage);
                              }