Posts Tagged ‘Snippets’

AS3 – Email validation RegEx

Monday, June 15th, 2009
1
/^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)+)@(([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)){2,}\.([A-Za-z]){2,4}+$/g

Found at http://www.gskinner.com/RegExr/

AS3 – XML Namespace

Thursday, May 7th, 2009

There are two ways to define namespaces :

1. The namespace is defined in the tag with theĀ attribute named “xmlns”.

XML :

1
2
3
4
5
6
<enclosure xmlns="http://www.solitude.dk/syndication/enclosures/">
 <title>Firenze</title>
 <link length="1" type="image/png">
  <url>http://kuler-api.adobe.com/kuler/themeImages/theme_24198.png</url>
 </link>
</enclosure>

2. The namespace is defined in a parent node with the attribute xmlns, and defines the prefix of the namespace that can be used later. In this example, there are three namespaces defined with the prefixes “xs”, “kuler” and “rss”.

XML :

1
2
3
4
5
6
7
8
9
<rss version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:kuler="http://kuler.adobe.com/kuler/API/rss/" xmlns:rss="http://blogs.law.harvard.edu/tech/rss">
 <channel>
  <link>http://kuler.adobe.com/</link>
  [...]
  <item>
   <kuler:themeItem>
    <kuler:themeID>24198</kuler:themeID>
    <kuler:themeTitle>Firenze</kuler:themeTitle>
    [...]

In Actionscript, to access a tag that is contained in a namespace, you create an instance of the Namespace class and then you access the node as you would normally do using the dot syntax, but you use the prefix of the namespace followed by “::” to indicate that it’s in that namespace :

AS3 :

1
2
var kuler:Namespace = new Namespace("http://kuler.adobe.com/kuler/API/rss/");
var title:String = xml_data.item.kuler::themeItem.kuler::themeTitle;

AS3 – Color functions

Friday, April 24th, 2009

This class lets you manipulate color information.

(more…)

AS3 – Trigonometry

Friday, April 24th, 2009

Here are some useful functions when working with angles and distances.

(more…)

AS3 – attachMovie equivalent using getDefinitionByName

Thursday, April 23rd, 2009

When you want to add a symbol from the library to a DisplayObject, you can easily do so with :

1
2
var class_instance:MovieClip = new MyClass();
do.addChild(class_instance);

Where MyClass is the class of the symbol. But when you need to pass a string as the class name (as we did with attachMovie in AS2), you can do so by using getDefinitionByName to get a reference to the class :

1
2
3
4
5
import flash.utils.getDefinitionByName;

var class_def:Class = getDefinitionByName("MyClass") as Class;
var class_instance:MovieClip = new class_def();
my_do.addChild(class_instance);