Hi guys
I have a question, something to do with the AS3 class. So staight to the point, everytime i create a looping statement that adds a movieclip object(with a class property) on an AS3 class i created, an ‘Error: Stack overflow occured’ happens. I wanna know why is it happening. Coz when i create my looping statement on the fla, it runs perfectly.
Here’s the code on the fla:
import microbox;
for(var i = 1; i <= 10; i++) { // determines which row should boxes start
for (var j = 1; j <= 16; j++) { // determines which column should boxes start
var mB:microbox = new microbox();
mB.x = (j - 1) * 10; // starting x-coordinate for the current microbox created
mB.y = (i - 1) * 10; // starting y-coordinate for the current microbox created
addChild(mB); // adds the box to the display list
}
}
this one runs perfectly.
Here’s the class code on microbox, nothing special here. (its just a small box movieclip on the fla):
package {
import flash.display.*;
import flash.utils.*;
import flash.events.*;
public class microbox extends MovieClip {
public var _root = MovieClip;
public function microbox() {
this.addEventListener(Event.ADDED, beginClass, false, 0, true);
}
public function beginClass(e:Event) {
_root = MovieClip(root);
}
}
}
And here’s what i’m trying to experiment on. name of class file is microboxClass:
package {
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import flash.text.*;
import microbox;
// Start of Class
public class microboxClass extends MovieClip {
private var microboxContainer:Sprite = new Sprite();
public function microboxClass() {
addEventListener(Event.ADDED, beginClass);
}
private function beginClass(e:Event) {
for(var i = 1; i <= 10; i++) {
for (var j = 1; j <= 16; j++) {
var mB:microbox = new microbox();
mB.x = (j - 1) * 10;
mB.y = (i - 1) * 10;
microboxContainer.addChild(mB);
}
}
addChild(microboxContainer);
}
}
}
So basically, what i do next is import the microboxClass on the fla, place it in a var then addChild that var. that’s when the stack overflow error happens. I just want to be enlightened if its possible to do this kind of looping statement on a class or why error occurs.
Thanks.
Zen
EDIT: typo error on the microboxClass, i edited it.