Flash / Flex / ActionScript/Language/package

Материал из Web эксперт
Версия от 11:15, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

A package-level function

   <source lang="java">

package com.example.shape {

   public function testShapes():void
   {
       trace("test the shapes here...");
   }

}

       </source>
   
  


Global Scope: Code placed directly outside a package body or at the top-level of a package body resides in the global scope.

   <source lang="java">

package {

 // Code here is in the global scope

} // Code here is also in the global scope package {

 // Definitions here are accessible to all code in the global scope

} // Definitions here are accessible to all code in the same source file

       </source>
   
  


Import all the classes in a particular package by using the wildcard operator (*) trailing the package name

   <source lang="java">

package {

   import com.example.shapes.*;
   public class PackagesTest
   {
       public function PackagesTest()
       {
           var r:Rectangle = new Rectangle();
           10 + DEFAULT_SIZE;
           testShapes();
       }
   }

} package com.example.shapes {

   public const DEFAULT_SIZE:int = 256;

} package com.example.shapes {

   public class Rectangle
   {
       // define Rectangle here.
   }

}

       </source>
   
  


package level function

   <source lang="java">

package {

 import flash.display.Sprite;
 public class CallPackagedFunction extends Sprite {
   public function CallPackagedFunction() {
     PackagedFunction(graphics);
   }
 }

} package {

 import flash.display.Graphics;
 public function PackagedFunction(target:Graphics):void {
   target.lineStyle(0);
   target.lineTo(100,100);
 }

}

       </source>
   
  


Packages groups classes

   <source lang="java">

package com.example.shapes {

   public class Rectangle
   {
       // define Rectangle here.
   }

} class SecretClass {

   // define SecretClass here.

}

       </source>
   
  


References to the classes by using their full name

   <source lang="java">

package {

   import com.example.shapes.Rectangle;
   import flash.geom.Rectangle;
   public class PackagesTest
   {
       public function PackagesTest()
       {
           var a:com.example.shapes.Rectangle =
               new com.example.shapes.Rectangle();
           var b:flash.geom.Rectangle =
               new flash.geom.Rectangle();
       }
   }

}

package com.example.shapes {

   public class Rectangle
   {
       // define Rectangle here.
   }

}

       </source>
   
  


The general form of a package definition directive

   <source lang="java">

package packageName { } To add a class to a package package packageName {

 Class source code goes here

} To create a new class: use a class definition class Identifier { } package com.wbex {

 class MyClass {
 }

}

       </source>
   
  


To gain access to all the public classes in another package.

   <source lang="java">

import packageName.*

       </source>
   
  


Variables, functions, and namespace declarations can also be contained inside packages.

   <source lang="java">

package com.example.shapes {

   public const DEFAULT_SIZE:int = 256;

}

       </source>