4 Replies Latest reply on Jun 24, 2010 10:07 PM by BhaskerChari

    Actionscript Graphics in MXML File

    Warentester

      Hello everyone,

       

      I wrote a simple Actionscript Class that draw some Stuff,

      now i want to see this on Screen, but i have no idea how it works.

       

      I think it's quite a simple one, it would be great if you could help me out.

       

      Here is the Action-Script-Class.

       

      public class GreetingsApp extends Sprite
          {
              public function GreetingsApp()
              {
                  var rectAndCircle:Shape = new Shape();
                  rectAndCircle.graphics.lineStyle(1);
                 
                  rectAndCircle.graphics.beginFill(0xff0000, 1);
                  rectAndCircle.graphics.drawRect(125,0,150,75);
                 
                  rectAndCircle.graphics.beginFill(0xff0000,1);
                  rectAndCircle.graphics.drawCircle(50,100,50);
                 
                  rectAndCircle.x = 125;
                  rectAndCircle.y = 100;
                 
                  addChild(rectAndCircle);
                 
              }
          }
      }

       

      I want to use it in a simple MXML-File.

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" >
         
          <fx:Declarations>
              <!-- Platzieren Sie nichtvisuelle Elemente (z. B. Dienste, Wertobjekte) hier -->
          </fx:Declarations>
          <s:BorderContainer>
              <!-- Here i would like to see the Greetings-App -->
          </s:BorderContainer>
      </s:Application>

       

      Thanks a lot for the Help

       

      Markus

        • 1. Re: Actionscript Graphics in MXML File
          BhaskerChari Level 4

          Hi Warentester,

           

          First create an instance of your GreetingsApp class and do the following:

           

          private var greetingsApp:GreetingsApp = new GreetingsApp();

           

          var uiComp:UIComponent = new UIComponent();
          uiComp.addChild(greetingsApp);
          borderContainerId.addChild(greetingsApp);

           

          Hope this works for you...

           


          If this post answers your question or helps, please kindly mark it as such.


          Thanks,

          Bhasker Chari

           

          • 2. Re: Actionscript Graphics in MXML File
            Warentester Level 1

            Hello  BhaskerChari,

             

            I'm really sorry but i don't catch it.

            It would be great if you could explain it in more detail

             

            .First create an instance of your GreetingsApp class and do the  following:

             

             

             

            With that you mean that i should put the code in the MXML-File ?

            Or create a new Actionscript-Class ?

             

            I'm really sorry for bothering you!

             

            Best Regards

             

            Markus

            • 3. Re: Actionscript Graphics in MXML File
              Flex harUI Adobe Employee

              I don't see calls to endFill().

               

              Try extending Group or SpriteVisualElement instead of Sprite

              • 4. Re: Actionscript Graphics in MXML File
                BhaskerChari Level 4

                Hi Markus,

                 

                No need of creating another mxml file or an Actionscript file...

                 

                Write the actionscript code which I gave you with in your mxml file in one function ....in a script block and call that function in any event say creationComplete() or applicationComplete() as you wish or your application needs..

                 

                Also Please include the below line of code in your ActionScript class that you wrote at the end..

                 

                rectAndCircle.graphics.beginFill

                 

                 

                Thanks & Regards,

                Bhasker Chari