AS3?  No.  The docs have gotten fubarred over the weekend.

XML?  Sure.

http://www.w3schools.com/xml/xml_namespaces.asp

In short, namespaces provide a way to avoid element naming conflicts.  For 
XML to valid (not well formed, 2 different things), all elements must have a 
common meaning.  Namespaces provide one way to set that context and meaning 
between 2 nodes with the same name.

For example, in Flex, if I create a button component, I differentiate 
between Flex' internal button, and mine via a namespace which points to my 
classpath.

<mx:Button />

<jxl:Button />

The namespace can be defined inline in my component:

<jxl:Button xmlns:jxl="com.jxl.view.controls.*" />

Or, and better practice, up top in the Application tag (a.k.a. root of the 
document):

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
 xmlns:mx="http://www.macromedia.com/2003/mxml";
 xmlns:jxl="com.jxl.view.controls.*" />

   <mx:Button />
   <jxl:Button />

</mx:Application>

...as far as AS3, the examples I've used in my talks are based on 
localization and versioning.  While they sound great in theory, I really 
don't see myself using them, but it's still early in the game, so who knows.

First, define it:

namespace en;

Next, declare a property as using the namespace:

en greeting:String = "Hello";

Finally, use it in a block of code, and all lines below will use that 
namespace:

use namespace en;
flash.util.trace(greeting); // Hello

So, if you were supporting multiple languages, you could do:

namespace eb;
eb greeting:String = "Yo";
use namespace eb;
flash.util.trace(greeting); // Yo

Same greeting variable inside of same class, different namepace

The same technique can be utilized on methods, such as:

namespace version1;
namespace version2;

version1 public function getValue():int
{
    return 1;
}

version2 public function getValue():int
{
    return 2;
}

import flash.util.trace;
use namespace version1;
trace(getValue()); // 1
use namespace version2;
trace(getValue()); // 2

Hope that helps.



----- Original Message ----- 
From: "bryan.rice" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <[email protected]>
Sent: Sunday, January 29, 2006 12:01 PM
Subject: [Flashcoders] XML Namespace Explanation in Simple Terms?


Hi All,

I need to explain XML namespaces to several marketing people and I
having trouble coming up with a layman's definition that is not too
technical.  I realize that it has to be at least a little technical,
but it was challenging to get them to literally understand what XML
was and then conceptually understand the extensible part.

Can you point me to any good explanations/tutorials about XML
namespaces?  Also, can anyone point me to explanations of how
namespaces are an important addition to AS 3.0?  I am trying to lay
the groundwork for an AS3 research project that I want them to fund.

blue skies,
bryan
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders 

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to