Tuesday, April 15, 2008

Prana Jumpstart

For everyone who wants to start using prana here is a (very) short tutorial.

1. Join the mailing list for all your questions: http://www.pranaframework.org/?page_id=4
2. Download the latest prana release: http://www.pranaframework.org/?page_id=5
3. Copy the prana.swc file from the bin dir to your projects lib dir and add the swc to your project in flexbuilder.
4. Create a file named applicationContext.xml in your projects source directory.
5. Check some samples to see what the xml file should look like and check the API: http://www.pranaframework.org/?page_id=2
6. Use an XmlObjectDefinitionsLoader to load the applicationContext.xml file and start to retrieving objects from the context.

Thats it, i'll add some code samples:

I created a utility class to retrieve objects from prana:
private var _objectsLoader:IObjectDefinitionsLoader;

public function loadContext(context:String):void {
// an instance of XmlObjectDefinitionsLoader is able to load an XML
// file with object definitions and parse it to an object container
_objectsLoader = new XmlObjectDefinitionsLoader();

// listen for the object definitions loader to complete
// (loaded and parsed xml object definitions)

// start the loading and specify the location of the object definitions

private function onLoadApplicationContextComplete(event:Event):void {
dispatchEvent(new Event(LOADING_COMPLETE));
Logger.info("Prana application context loading complete.");

public function getObject(beanName:String) : Object {
return _objectsLoader.container.getObject(beanName);

You can define two objects that depend on each other like this:
<object id="userController" class="nl.quintor.university.user.controller.UserController">
<constructor-arg ref="userModel"/>

<object id="userModel" class="nl.quintor.university.user.model.UserModel">

written by Marcel Panse

No comments: