Hi,
I have been doing something similar with a site that I am building.
There is a "shell" application that loads up various swfs into a holder
clip. The application needs to be able to talk to these loaded clips
and do stuff to them. The way I have worked it is to load up a SWF
which has a movieclip on stage linked to a "Page" class. When the page
class is ready (see the setInterval call) it will call a function on the
parent movie clip called "registerPage" at that point the parent movie
clip ("ApplicationForm") can start calling methods on the class. I am
not sure if there is a better way of doing this, but I have found that
loaded clips seem to take a few milliseconds to actually initialise
properly so that I can actually call my own methods on them - hence
putting in the waitOnLoad function. If anyone knows how to do this in
an easier way, please tell me.
Thanks
Glen
See stripped down code:
//ApplicationForm class
import org.osflash.arp.log.Log;
import mx.utils.Delegate;
/**
* ApplicationForm class
* This is the meat of our website and deals with loading pages in
* response to events that come from a menu - @see MenuForm implements
* the functionality to deal with this.
*/
class ApplicationForm extends EventDispatcherForm //implements the
EventDispatcher mixin
{
//
// Group: On Stage
//
private var mPageHolder:MovieClip;
//
// Group: Properties
//
//Handle loading of external resources.
private var mLoader:MovieClipLoader;
private var mLoading:Boolean;
//Keep track of the page we are on - so we can call functions on it.
private var mCurrentPage:Page;
private var mSwfToLoad:String;
function ApplicationForm ()
{
stop();
}
/**
* registerPage is called by a "Page" child movie clip when it is loaded
* this means that the class linked to the clip will have been fully
defined
* and can have methods called on it.
* @param pPage reference to a Page movieclip that has been loaded
into
* the "PageHolder" from an external SWF.
*/
public function registerPage(pPage:Page):Void {
Log.debug("ApplicationForm::registerPage " + pPage);
//trace("registerPage " + pPage);
mCurrentPage = pPage;
mCurrentPage.addEventListener("pagevis", Delegate.create(this,
pageVisibility));
mCurrentPage.show();
}
/**
* onLoad - we do our initialisation in here rather than in the
constructor because
* any clips on stage will be initialised too - make sure the "load
order" for the
* FLA is "Bottom Up" otherwise this is not true.
*/
function onLoad ()
{
// Initialize the LuminicBox Logger
Log.initialize();
// Note: This handler is used to initialize the application state.
Log.warn ("ApplicationForm::onLoad - Application initialization
started!");
mLoader = new MovieClipLoader();
//etc
}
/**
* EventHandler for a "pagevis" event dispatched by a Page class - this
* means it has either done it's intro animations and is ready to do
stuff or
* has done it's exit animations and is actually hidden.
* If it is hidden - we are waiting to load a new page. If it is
visible, we change
* the flag to say we are allowed to load a different page.
* @param evt
*/
private function pageVisibility(evt:Object):Void {
Log.it("ApplicationForm::pageVisibility " + evt.target + ", " +
evt.visibility);
if(false == evt.visibility) {
//page is "hidden", load the next
_loadSwf(mSwfToLoad);
} else {
//tell everyone we have finished loading..
loading = false;
}
}
/**
* Call to start loading an external SWF into the "PageHolder" clip.
* @param swfName
*/
private function _loadSwf(swfName:String) {
Log.it("ApplicationForm::Loading swf " + swfName + " into " +
mPageHolder);
loading = true;
mLoader.addListener(this);
mLoaderForm.percent = 0.0;
mLoaderForm.visible = true;
mLoader.loadClip(swfName, mPageHolder);
}
/**
* Implement Listener functions for the MovieClipLoader object.
*/
//etc...
}
/**
* Page class is a movieclip that is loaded into the ApplicationForm from
* an external SWF.
*/
import org.osflash.arp.log.Log;
class Page extends EventDispatcherForm
{
//
// Group: Properties
//
private var mWaitInterval:Number;
function Page ()
{
stop();
}
/**
* Accessor for the _visible parameter
* @param vis
*/
public function set visible(vis:Boolean):Void {
_visible = vis;
}
public function get visible():Boolean { return _visible; }
/**
* Called by the parent movie clip to "show" this one - starts off a
Tweening
* process - sort of an intro.
* @param evt
*/
public function show(evt:Object) {
Log.debug("Page::show");
/*
* Do intro
*/
}
/**
* Called by the parent movie clip to "hide" this one - starts off a
Tweening
* process - sort of an outtro.
* @param evt
*/
public function hide() {
/*
* Do "outro
*/
}
////////////////////////////////////////////////////////////////////////////
//
// Method: onLoad()
//
// Called when all child movie clips and components have initialized.
//
////////////////////////////////////////////////////////////////////////////
function onLoad ()
{
Log.initialize();
// Note: This handler is used to initialize the application state.
Log.warn ("Page::onLoad - Page initialization started!");
//trace("me " + this + " parent " + _parent);
if(_parent._parent) {
visible = false;
}
mWaitInterval = setInterval(this, "waitOnLoad", (10));
}
/**
* Basically we have to wait a few milliseconds after a SWF has
finished loading
* before it is properly initialised - onLoad is a bit of a fallacy
for some reason.
* So this is where we do the actual initialisation - called when an
interval set
* above ( @see onLoad ) expires
*/
function waitOnLoad() {
Log.debug("Page::waitOnLoad " + this._parent);
clearInterval(mWaitInterval);
//Tell the parent we are here..
_parent._parent.registerPage(this);
}
}
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com