5 Replies Latest reply on Dec 13, 2010 11:00 AM by GordonSmith

    Static class definition in flex

    ravi burila Level 1

      Hi friends,

       

      can any one,please provide me with some example of defining static class in flex and acessing it in mxml page.

      one more thing i want to make clear,static class is nothing but .as class. Am i Right?

       

      thanks in Advace!!!!

        • 1. Re: Static class definition in flex
          drkstr_1 Level 4

          Classes aren't static in themselves. They have methods and properties that can be static.

           

          Main.mxml

          <?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" 
                                 creationComplete="creationCompleteHandler(event)" >
               <fx:Script>
                    <![CDATA[
                         import com.util.HelloCommand;
                         
                         import mx.events.FlexEvent;
          
                         protected function creationCompleteHandler(event:FlexEvent):void
                         {
                              HelloCommand.execute();
                         }
          
                    ]]>
               </fx:Script>
          </s:Application>
          

           

          com/util/HelloCommand.as

          package com.util
          {
               public class HelloCommand
               {
                    public static function execute():void
                    {
                         trace("Hello World");
                    }
               }
          }
          

          • 2. Re: Static class definition in flex
            ravi burila Level 1

            may u know what is the difference between mx: and s:

             

            <mx:Application>

             

             

            <s:Application

            • 3. Re: Static class definition in flex
              ravi burila Level 1

              i tried but nothing displayed on screen

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application  xmlns:mx="http://www.adobe.com/2006/mxml"
                                     creationComplete="creationCompleteHandler(event)">
                   <mx:Script>
                        <![CDATA[
                             import com.util.HelloCommand;
                            
                             import mx.events.FlexEvent;

               

                             protected function creationCompleteHandler(event:FlexEvent):void
                             {
                                  HelloCommand.execute();
                             }

               

                        ]]>
                   </mx:Script>
              </mx:Application>

               

               

              package com.util
              {
                  public class HelloCommand
                  {
                      public static function execute():void
                        {
                             trace("Hello World");
                        }

               

               

               

                  }
              }

              • 4. Re: Static class definition in flex
                Claudiu Ursica Level 4

                The trace statement shows in the console not on the screen.

                C

                • 5. Re: Static class definition in flex
                  GordonSmith Level 4

                  > may u know what is the difference between mx: and s:

                   

                  Flex actually has two sets of components, the original "MX" components from Flex 1.0 and the newer "Spark" components introduced in Flex 4.0. The Spark components support a much better skinning model.

                   

                  In terms of ActionScript classes, the two versions of Application are mx.core.Application and spark.components.Application. The MXML tags that map to these classes are normally written as <mx:Application> and <s:Application>, although the mx: and s: prefixes are completely arbitrary. What is important is the URIs declared for xmlns:mx="..." and xmlns:s="...". These URIs represent the SWCs containing these components, and the SWCs have "manifest" information about the mapping of tags to classes.

                   

                  Gordon Smith

                  Adobe Flex SDK Team