-
[RESOLVED] addChild not workiing inside my Class
I'm a noob in AS3 and I'm trying to learn OOP. I'm trying to add a movieclip from my library using a class.
In my fla I have a movieclip symbol in the library with a class name of "preloader".
I have an .as file named Preloader - when I try to place this symbol on the stage using this class I see nothing and get no error messages. The code in my Preloader class file:
package{
import flash.display.Sprite;
public class Preloader extends Sprite{
public function Preloader(){
addChild(new preloader()).name = "preload_mc";
}
}
}
The code in my fla:
var myPreloader:Preloader = new Preloader();
Why is my preloader mc not showing up?
-
Does the case match? You said the class name in the library is "preloader", but the .as class is "Preloader". What is probably happening is that Flash is implicitly defining a "preloader" class for you because it doesn't find one. Rename one or the other.
Edit: Also, that script you posted doesn't make sense to me. At all.
-
The class of the symbol in my library could really be anything - I'm just trying to figure out how to add something from my library to the stage using a class
-
Oh, so you did intend them to be separate. The naming was confusing. I will hereafter refer to "preloader" as "Bruce", just to keep it clear.
In that case, it looks pretty good. I bet what's happening is that you never put your Preloader on the stage. You can resolve this two ways. First, you could do this in your fla:
Code:
var myPreloader:Preloader = new Preloader();
addChild(myPreloader);
OR, you could simply make your document class for the fla set to Preloader.
-
Yep, that did it...thanks a lot! I'm trying to my head around the whole addChild thing.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|