Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Show Posts

| * |

  Show Posts
Pages: [1]
1  Announcements and General Discussion / General Discussion / how to load my pureMVC adr_book.swf into a preloader.swf on: August 22, 2007, 04:27:11
Hi Cliff,

I've just accomplished my first working pureMVC test project. It just loads some address data from a mysql db into a datagrid using AMFPHP 1.9. It works just fine.

So far I have been using Aral Balkans ARP for my AS2 projects, but I think I'm definitely going to use your framework in the future.

Today I tried to use an external preloader to load my adr_book.swf but it generated this error in my flash cs3 output panel (tracing class contructors):

:
DataProxy constructed
StageMediator constructed
TypeError: Error #1009: Der Zugriff auf eine Eigenschaft oder eine Methode eines null-Objektverweises ist nicht möglich.
at com.malo.adr_book.view::StageMediator$iinit()
at com.malo.adr_book.controller::StartupCommand/execute()
at org.puremvc.core.controller::Controller/executeCommand()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at org.puremvc.patterns.observer::Observer/notifyObserver()
at org.puremvc.core.view::View/notifyObservers()
at org.puremvc.patterns.facade::Facade/notifyObservers()
at com.malo.adr_book::Adressbook$iinit()

What's the problem? I  used Colin Mooks loader example(Essential ActionScript 3.0, p.778) and made it the document class for preloader.fla

:
package
{
import flash.display.*;
import flash.net.URLRequest;
import flash.events.*;
import flash.text.*;

public class LoadAdressBook extends MovieClip
{

private var loader:Loader;// the asset loader
private var progressOutput:TextField;// textfield to display lad progress

// constructor
public function LoadAdressBook()
{

// create loader object and register for events
createLoader();

// create progress indicator
createProgressIndicator();

// start load operation
load(new URLRequest("adr_book.swf"));

}
private function createLoader()
{
// create the loader
loader = new Loader();

// register for events
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progressListener);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeListener);
loader.contentLoaderInfo.addEventListener(Event.INIT,initListener);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrorListener);

}
private function createProgressIndicator():void
{
progressOutput = new TextField();
progressOutput.autoSize = TextFieldAutoSize.LEFT;
progressOutput.border = true;
progressOutput.background = true;
progressOutput.selectable = false;
progressOutput.text = "LOADING...";

}
private function load(urlRequest:URLRequest):void
{
// start load operation
loader.load(urlRequest);
// if progressOutput isn't already a descendant of this object ...
if (!contains(progressOutput))
{
// ... add it to display list
addChild(progressOutput);
}

}
private function progressListener(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";

}
private function initListener(e:Event):void
{
addChild(loader.content);

}
private function completeListener(e:Event):void
{
// remove progress indicator
removeChild(progressOutput);

}
private function ioErrorListener(e:IOErrorEvent):void
{
// evoked when a load error occurs
progressOutput.text = "LOAD ERROR";
}
}
}

This is the document class for my adr_book.fla ...

:
/**
* document class for adr_book project
*
* uses PureMVC framework
*/
package com.malo.adr_book
{
import flash.display.MovieClip;
import flash.display.Stage;
import com.malo.adr_book.ApplicationFacade;
import org.puremvc.patterns.observer.Notification;


public class Adressbook extends MovieClip
{

private var facade:ApplicationFacade;

public function Adressbook()
{
// Instantiate the ApplicationFacade
var facade:ApplicationFacade = ApplicationFacade.getInstance();

// Send the STARTUP notification
var note:Notification = new Notification( ApplicationFacade.STARTUP, this.stage);
facade.notifyObservers(note);

}

}
}

... here comes the ApplicationFacade.as

:
package com.malo.adr_book
{
    import org.puremvc.interfaces.IFacade;
    import org.puremvc.patterns.facade.Facade;
    import com.malo.adr_book.controller.*;
   
    public class ApplicationFacade extends Facade implements IFacade
    {
        // Notification name constants
        public static const STARTUP:String  = "startup";
public static const GET_ALL_CONTACTS:String = "get_all_contacts";
        public static const DATA_UPDATE:String  = "data_update";
public static const SHOW_INTRO_FORM:String  = "show_intro_form";
public static const SHOW_CONTACTS_FORM:String  = "show_contacts_form";

/**
         * Singleton ApplicationFacade Factory Method
         */
        public static function getInstance() : ApplicationFacade {
            if ( instance == null ) instance = new ApplicationFacade( );
            return instance as ApplicationFacade;
        }

        /**
         * Register Commands with the Controller
         */
        override protected function initializeController( ) : void
        {
            super.initializeController();           
            registerCommand( STARTUP, com.malo.adr_book.controller.StartupCommand );
registerCommand( GET_ALL_CONTACTS, com.malo.adr_book.controller.GetAllContactsCommand );
registerCommand( DATA_UPDATE, com.malo.adr_book.controller.DataUpdateCommand );
        }
       
    }
}

and finally the StartupCommand.as

:
package com.malo.adr_book.controller
{
import flash.display.Stage;
import org.puremvc.interfaces.ICommand;
import org.puremvc.interfaces.INotification;
import org.puremvc.patterns.command.SimpleCommand;

import com.malo.adr_book.ApplicationFacade;
import com.malo.adr_book.view.*;
import com.malo.adr_book.model.DataProxy;

public class StartupCommand extends SimpleCommand implements ICommand
{
/**
* Register the Proxies and Mediators.
*
* Get the View Components for the Mediators from the app,
* which passed a reference to itself on the notification.
*/
override public function execute( note:INotification ):void
{
facade.registerProxy(new DataProxy());

var stage:Stage = note.getBody() as Stage;
facade.registerMediator( new StageMediator( stage ) );

}
}
}

I apologize for all this code here. I'd rather uploaded my zipped example project, but it's 839 KB.

I hope this is sufficient info for anybody to help me with the preloader problem

greetings from bavaria

martin

Pages: [1]