This tutorial demonstrates how to load and manipulate (resize in this example, but once you have access to the API you can do a whole lot of other things) FlashPaper 2.0 SWF files with ActionScript 2.0.
You will need:
- Flash MX 2004 or Flash 8
- FlashPaper 2.0
Click here to see the example in action.
Click on the attachment to download sample files.
In this example, we will simply load a FlashPaper 2.0 document and scale it to fit the size of our Flash Movie.
Here’s an article about using FlashPaper documents.
For more details see the documentation on the FlashPaper API.
Add the following code to the first frame of your movie.
// Creating the MovieClip into which we’ll load our Flash Paper document.
this.createEmptyMovieClip( "testMovie_mc", this.getNextHighestDepth() );
// callback functions for this clip
var mcObjListener = new Object();
mcObjListener.onLoadComplete = function(){
testMovie_mc._visible = false;
}
mcObjListener.onLoadInit = function( arg_target:MovieClip ):Void{
trace( "running the onLoadInit callback" );
trace( "arg_target = " + arg_target );
// We’ll have to wait until the first page of the flash paper document has loaded
// before we have access to the FlashPaper API
// To do so, we’ll set up an interval that will check for it’s existence.
// Then run the setSize method
var var_intervalID = 0;
// Our check function
function checkFlashPaperLoaded(){
// Hide the holder clip until it is loaded
// eval( arg_target )._visible = false;
// Getting a reference to our FlashPaper object
var var_flashPaperObj = eval( arg_target ).getIFlashPaper();
trace( "var_flashPaperObj = " + var_flashPaperObj );
if( !var_flashPaperObj ){
return;
}
else{
trace( "We now have access to our FlashPaper API" );
clearInterval( var_intervalID );
// Resize the doc
var_flashPaperObj.setSize( 800, 600 );
// Show it
eval( arg_target )._visible = true;
}
}
var_intervalID = setInterval(checkFlashPaperLoaded, 100);
};
// Here we create a new MovieClipLoader Object
var var_movieClipLoader = new MovieClipLoader();
// Here we add the listener to our new MovieClipLoader Object
var_movieClipLoader.addListener( mcObjListener );
// Now we use our new MovieClipLoader object to load the swf into the movieclip holder
var_movieClipLoader.loadClip( "build.it.and.then.tell.them.swf", "testMovie_mc" );
Make sure you have a FlashPaper 2.0 SWF of the appropriate name in the same directory and compile to see you document in Flash.
Remember that the FlashPlayer security settings will not allow you to view this example in a browser locally. To see it in a browser, publish a .html file with it and post to your webserver.