 ugar Guest |
Quote
|
2009-04-23 17:52:51 |
|
Hi,
CopperCube is great, but is there a way to create just one single SWF file when I am using the Actionscript 3 scripting feature to move some objects in the scene? Tried to embedd it, but it doesn't seem to work for me..
|
 niko Moderator |
Quote
|
2009-04-23 18:00:05 |
|
hi,
that's actually quite simple, you can use the the flex embed tag for this. If you additionally want to use the simpleAPI, flash might give you the runtime error 1069, because it forbids to invoke methods of embedded swf files, so instead embedd the file as binary and load it using a loader, like here:
package { import flash.display.* import flash.net.URLRequest; import flash.events.Event; import flash.events.KeyboardEvent; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.events.IOErrorEvent; import flash.events.MouseEvent; import flash.utils.ByteArray; [SWF(width="640", height="480", frameRate="100", backgroundColor="000000")] public class main extends Sprite { // The CopperCube generated SWF file. Embedded into this file here so we get only one single SWF [Embed(source="resources/3dscene.swf", mimeType="application/octet-stream")] public static var EmbeddedCopperCubeSWFDataFile:Class; private var loader:Loader; private var coppercubeSprite:DisplayObject; private var simpleAPI:Object; private var fpsTextField:TextField; private var loadingFinished:Boolean; public function main() { addEventListener(Event.ENTER_FRAME, onGraphicsFrame); // load the coppercube scene from the other swf var copperCubeData:ByteArray = new EmbeddedCopperCubeSWFDataFile() as ByteArray; loader = new Loader(); addChild(loader); loader.loadBytes(copperCubeData); loader.contentLoaderInfo.addEventListener(Event.INIT, onCoppercubeLoaded); // add a text field to show the status fpsTextField = new TextField(); fpsTextField.textColor = 0x444444; fpsTextField.selectable = false; fpsTextField.wordWrap = false; fpsTextField.multiline = false; fpsTextField.autoSize = TextFieldAutoSize.LEFT; fpsTextField.text = "Loading..."; addChild(fpsTextField); } // called when the coppercube .swf file has been loaded and initialized private function onCoppercubeLoaded(e:Event):void { // get access to the simple API object: coppercubeSprite = loader.content as DisplayObject; loadingFinished = true; } // called every frame public function onGraphicsFrame(event:Event):void { if (loadingFinished) { if (!simpleAPI && coppercubeSprite) simpleAPI = coppercubeSprite['simpleAPI']; if (simpleAPI && simpleAPI.isLoaded()) { // display frames per second of your scene fpsTextField.text = "Frames per Second: " + simpleAPI.getFramesPerSecond() + "\n(CopperCube Beta Version)"; } } } } }
|