现在的位置: 首页 > 综合 > 正文

AS3中的名称空间namespace

2012年07月22日 ⁄ 综合 ⁄ 共 1439字 ⁄ 字号 评论关闭

1.一般应用(访问名称空间下方法)

use namespace mx_internal;

var textArea:TextArea = TextArea();

textArae.htmlText="<b>test</b>";

var itf:IUITextField=textArae.getTextField();

2.不同名称空间相同的函数签名

package
{
 import flash.display.Sprite;
 
 public class NamespaceExample extends Sprite
 {
     public namespace French;
     public namespace Hawaiian;
     public function NamespaceExample() {
        trace(Hawaiian::hello()); // aloha
        trace(French::hello()); // bonjour
     }
     Hawaiian function hello():String {
         return "aloha";
     }
 
     French function hello():String {
         return "bonjour";
     }
 }
}

3.名称空间下的函数重写

package
{
 public class ns2 extends NamespaceExample
 {
  use namespace French;
  public function ns2()
  {
   French::hello();
  }
  French override function hello():String {
         return "bonjour";
     }
 }
}

4.接口不允许使用名称空间

package
{
 public interface I1
 {
  public namespace French;
  French function hello();
 }
}

Severity and Description Path Resource Location Creation Time Id
1166: 不允许在接口中使用 namespace 声明。 test I1.as line 5 1217302934515 13427

5.xml处理中使用名称空间

一个adobe给的例子

 

var soap:Namespace = new Namespace("http://schemas.xmlsoap.org/wsdl/soap/");
var w:Namespace = new Namespace("http://weather.example.org/forecast");
var myXML:XML =
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<soap:Body>
<w:forecast xmlns:w="http://weather.example.org/forecast">
<w:city>Quito</w:city>
<w:country>Ecuador</w:country>
<date>2006-01-14</date>
</w:forecast>
</soap:Body>
</soap:Envelope>;
trace(myXML.soap::Body.w::forecast.w::city); // Quito

抱歉!评论已关闭.