Hi guys
I’m trying to make a preloader for my Flash movie that starts from zero percentage without using two flash files.
I tried to follow this solution: http://www.bit-101.com/blog/?p=946 but I can’t seem to get it to work. It always fails at runtime (not at compiletime). The runtime debugger throws this error (the first line is a trace I manually put in, code at end of this post):
FrameTest Constructor
TypeError: Error #1007: Instantiation attempted on a non-constructor.
at FrameTest/init()
at FrameTest$iinit()
Is this error a result of the “Embed(source)” tag?
Why is the Factory never called?
You’ll notice that I’ve put some traces in the code to see where it exactly crashes.
Here is what I did:
- I’ve set my document class to: FrameTest class which is in the same directory as my .fla
- Code of the two classes used (thanks to bit-101):
package {
import flash.display.Sprite;
import flash.display.Bitmap;
[Frame(factoryClass="com.arckodrazen.MyFactory")]
public class FrameTest extends Sprite {
[Embed(source="big_asset.jpg")]
private var Asset:Class;
public function FrameTest() {
trace("FrameTest Constructor");
init();
}
public function init():void {
var asset:Bitmap = new Asset();
addChild(asset);
}
}
}
package com.arckodrazen {
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.utils.getDefinitionByName;
public class MyFactory extends MovieClip {
public function MyFactory() {
trace("MyFactory Constructor");
stop();
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(event:Event):void {
trace("MyFactory onEnterFrame");
graphics.clear();
if(framesLoaded == totalFrames) {
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
nextFrame();
init();
} else {
var percent:Number = root.loaderInfo.bytesLoaded / root.loaderInfo.bytesTotal;
graphics.beginFill(0);
graphics.drawRect(0, stage.stageHeight / 2 - 10,
stage.stageWidth * percent, 20);
graphics.endFill();
}
}
private function init():void {
var mainClass:Class = Class(getDefinitionByName("FrameTest"));
if(mainClass){
var app:Object = new mainClass();
addChild(app as DisplayObject);
}
}
}
}
Thanks for any responses in advance.
Arcko Drazen