@ sectore
thanks a lot for your quick and helpful responses!
I got it working.
Both of your assumptions proofed to be true:
I think it could have to do with the LoaderContext or ApplicationDomain.
I think you have to call the initialize process of your PureMVC app after loading all content and not within the constructor of your "extern" document class named "Adressbook".
this is what my preloader class looks like now:
package
{
import flash.display.*;
import flash.net.URLRequest;
import flash.events.*;
import flash.text.*;
import fl.controls.Label;
import fl.controls.ProgressBar;
import fl.controls.ProgressBarMode;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
public class Preloader extends MovieClip
{
private var loader:Loader;// the asset loader
private var progressOutput:Label;// label to display lad progress
private var myProgressBar:ProgressBar;// progressbar component
// constructor
public function Preloader()
{
// create loader object and register for events
createLoader();
// create progress indicator
createProgressIndicator();
// start load operation
load(new URLRequest("addressbook.swf"));
}
private function createLoader()
{
// create the loader
loader = new Loader();
// register for events
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progressHandler);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
loader.contentLoaderInfo.addEventListener(Event.INIT,initHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
}
private function createProgressIndicator():void
{
progressOutput = new Label();
progressOutput.autoSize = TextFieldAutoSize.LEFT;
progressOutput.selectable = false;
progressOutput.text = "LOADING...";
// create myProgressBar
myProgressBar = new ProgressBar();
myProgressBar.height = 20;
myProgressBar.move(stage.stageWidth/2-myProgressBar.width/2,stage.stageHeight/2);
myProgressBar.mode = ProgressBarMode.MANUAL;
addChild(myProgressBar);
progressOutput.move(myProgressBar.x,myProgressBar.y - 20);
}
private function load(urlRequest:URLRequest):void
{
trace("Preloader::load()");
var loaderContext:LoaderContext = new LoaderContext();
loaderContext.applicationDomain = ApplicationDomain.currentDomain;
// start load operation
loader.load(urlRequest,loaderContext);
// if progressOutput isn't already a descendant of this object ...
if (!contains(progressOutput))
{
// ... add it to display list
addChild(progressOutput);
}
}
private function progressHandler(e:ProgressEvent):void
{
// update progress indicator. 1 kb is 1024 bytes, so divide by
// 1024 to convert output to kb
progressOutput.text = "LOADING: "
+ Math.floor(e.bytesLoaded / 1024)
+ "/" + Math.floor(e.bytesTotal /1024) + " KB";
myProgressBar.setProgress(e.bytesLoaded/1024,e.bytesTotal /1024);
}
private function initHandler(e:Event):void
{
trace("Preloader::initHandler()");
//addChild(loader.content);
}
private function completeHandler(e:Event):void
{
trace("Preloader::completeHandler()");
// remove progress indicator
removeChild(progressOutput);
// remove progressbar
removeChild(myProgressBar);
// opting out of compile time type checking
// therefore access external main class via event.target
var app:* = e.target.content;
// add content
addChild(app);
// init app
app.init();
//Adressbook(e.target.content).init(); // possible alternative for above
}
private function ioErrorHandler(e:IOErrorEvent):void
{
// evoked when a load error occurs
progressOutput.text = "LOAD ERROR";
}
}
}
... and here's the adapted document class of the loaded pureMVC project:
/**
* document class for address book project
*
* uses PureMVC framework
*/
package com.malo.addressbook
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.*;
import com.malo.addressbook.ApplicationFacade;
import org.puremvc.patterns.observer.Notification;
public class Addressbook extends MovieClip
{
private var facade:ApplicationFacade;
public function Addressbook()
{
trace("Addressbook constructed");
/**
* uncomment this for use without preloader.as
* ... and dont't forget to recompile adr_book.fla ;-)
*/
// init();
}
// is called from preloader.as after Event.COMPLETE is fired
public function init()
{
trace("Addressbook::init()");
// Instantiate the ApplicationFacade
var facade:ApplicationFacade = ApplicationFacade.getInstance();
// Send the STARTUP notification
var note:Notification = new Notification( ApplicationFacade.STARTUP, this.stage);
facade.notifyObservers(note);
}
}
}
thanks again, guys
greetings
martin