| Package | com.soma.assets |
| Class | public class Library |
| Implements | ILibrary |
Author: Romuald Quantin - www.soundstep.com
Information:
Blog page - SomaUI
How does it work - Soma Protest
Project Host - Google Code
Documentation - Soma ASDOC
Class version: 2.0
Actionscript version: 3.0
Copyright:
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied.
See the License for the specific language governing rights and
limitations under the License.
The Original Code is Soma.
The Initial Developer of the Original Code is Romuald Quantin.
Initial Developer are Copyright (C) 2008-2009 Soundstep. All Rights Reserved.
Usage:
A library instance allows you to register special assets that have the meaning to be instantiated from a NodeParser instance and an XML node.
The global Soma library is accessible using Soma.getInstance().library and 4 assets type are registered by default: text (SomaText), video (SomaVideo), bitmap and movieClip (from flash IDE library or SWC).
You can register a new asset class that must implement IAsset to be instantiated by a NodeParser instance:
Soma.getInstance().config.registerAsset("myAsset", MyAssetClass);
package com.somaprotest.assets {
import com.soma.interfaces.IAsset;
import com.soma.utils.SomaUtils;
import com.soundstep.ui.BaseUI;
import flash.display.DisplayObject;
public class CircleAsset implements IAsset {
public function instantiate(node:XML, baseUI:BaseUI = null):DisplayObject {
var circle:CircleParam = new CircleParam(10, 0x00FF00);
circle.name = node.@id;
SomaUtils.setProperties(circle, node);
if (baseUI != null) SomaUtils.setBaseUIProperties(circle, baseUI, node);
return circle;
}
}
}
package com.somaprotest.assets {
import flash.display.Sprite;
public class CircleParam extends Sprite {
public function CircleParam(radius:Number, color:uint) {
graphics.beginFill(color);
graphics.drawCircle(radius, radius, radius);
}
}
}
Soma.getInstance().library.registerAsset("circleParam", CircleAsset);
<circleParam id="myCircle" classname="CircleParam" x="10" y="10"/>
See also
| Method | Defined by | ||
|---|---|---|---|
|
Library()
Creates an Library instance, Soma has a global library accessible using Soma.getInstance().library.
| Library | ||
|
getAsset(name:String):Class
Get an asset class (IAsset) from its name, usually used by a NodeParser instance.
| Library | ||
|
registerAsset(name:String, asset:Class):void
Register a class with its name to be instantiated by a NodeParser instance from an XML node.
| Library | ||
| Library | () | constructor |
public function Library()Creates an Library instance, Soma has a global library accessible using Soma.getInstance().library.
| getAsset | () | method |
public function getAsset(name:String):ClassGet an asset class (IAsset) from its name, usually used by a NodeParser instance.
Parametersname:String — Name of the class (used when register).
|
Class — a Class.
|
| registerAsset | () | method |
public function registerAsset(name:String, asset:Class):voidRegister a class with its name to be instantiated by a NodeParser instance from an XML node.
Parametersname:String — name of the asset (will be used as an XML node name: <myAssetName />)
|
|
asset:Class — class implementing IAsset that will instantiate the asset using an XML node.
|