Skip navigation

Managing Code Loading with Fuse

Here is an example of using Fuse as a load manager. This works really well if you want to sequence code that needs to wait until something is loaded. It works great if you need to load xml before you draw the ui.

UPDATED 03-10-07: The code has been updated to fuse 2.

[as]

function drawLoadManager(){
trace(”Draw Load Manager Called”);
var lm = this.loadManager = new Fuse();
lm.scope = this;
lm.push({ func:”myMethodOne”});
lm.push({ command:”pause”});
lm.push({ func:”loadData”});
lm.push({ command:”pause”});
lm.push({ func:”loadMyClip”});
lm.start();
}

function myMethodOne(){

do some code…….

// resume the load manager to load the next item
this.loadManager.resume();
}

function loadData(){
this.xml = new XML();
this.xml.ignoreWhite = true;
// CREATE A REFERENCE TO THE CURRENT TIMELINE
this.xml._parent = this;
this.xml.onLoad = function () {
// resume the load manager to load the next item
this._parent.loadManager.resume();
}
this.xml.load(this.datafile);
}

function loadMyClip(){
this.myClip.loadMovie(load something);
// create some sort of load handler
this.myClip.onLoad(){
// resume the load manager to load the next item
this._parent.loadManager.resume();
}
}

[/as]

8 Comments

  1. Posted March 21, 2006 at 7:13 pm | Permalink

    Very cool :) And you could expand this by combining it with other Fuses that altered the state of a loading bar as the application loaded.

  2. Posted March 21, 2006 at 8:13 pm | Permalink

    Yep. Fuse is really cool. Lots of neat things you can do with it.

  3. Posted March 23, 2006 at 1:28 am | Permalink

    Interesting, this is close to what Im looking for. I am new to fuse and excited about its possibilities, however the code above throws an AS error for me around line 33. Im not sure why. So I couldn’t see it in action. It appears that this code will load an XML file and create clips but what about fading them in with a slight delay? Do you know how to do that? Thanks in advance. Forgive my newbiness on this I know how to do this in AS but I want to exploit Fuse to the fullest.

    Thanks in advance!

  4. Posted March 22, 2007 at 2:29 pm | Permalink

    UPDATE:
    For anyone reading the comment above it refers to older code and should not be a problem for anyone. Incase you are curious, it was due to changes in the core functionality of Fuse and therefore had to be coded differently.

  5. Posted June 9, 2007 at 9:09 am | Permalink

    Is it possible to start the “next” function with parameters that were created in the function before?

    Thx for the nice discription.

  6. Posted June 9, 2007 at 9:51 pm | Permalink

    The short answer is yes. I would take a look at the Fuse docs. search the page for “args”.

  7. Posted June 10, 2007 at 4:19 am | Permalink

    Ok. Thank you. I have now found that i can use for example func:”trace” with the arg:”Now”. But how can i get the arg from my “last” function for the “next” function? Is it possible to take “this._parent.loadManager.resume();” to start the next function with any parameter?

  8. Chris
    Posted June 22, 2007 at 5:29 am | Permalink

    Assuming you plan to run the methods in sequence, you could always create an variable of type object and just assign parameters and values to it. That way you can just call that variable within the fuse/function of your choice. So long as the object is declared at the start of your actionscript, I would guess that it would work the way you want… albeit in a very primitive fashion. Once fuses start running in parallel then you could get potential synchronization issues where parameters wouldn’t be set, or have the wrong values.

Post a Comment

You must be logged in to post a comment.