0
votes

ive been working on a projects that needs to use childs (for background stars). In the line that adds the child, i keep getting an error. The error is as follows: Scene 1, Layer 'Menu Interface', Frame 1, Line 23, Column 23 1067: Implicit coercion of a value of type Class to an unrelated type flash.display:DisplayObject. The code which it refers to is:

    for (var i:int = 0; i < 50; i++)
{
    MenuSpawner.addChild(stars);
}

Line 23 is the MenuSpawner one. Thanks, James

1

1 Answers

0
votes

The stars here seems to be a reference to the class. Class is an abstraction. What you can actually put on display list are instances. What you probably need to do is

for (var i:int = 0; i < 50; i++)
{
    var aStar:DisplayObject = new stars;
    MenuSpawner.addChild(aStar);
}

So, this code adds 50 instances of stars class to the MenuSpawner container. You don't set their coordinates in this code so they all will probably go to (0,0).

Also, classes name should start with uppercase letter. Lowercase is not an error, just disg... ahem, they look like variable names, so confusing.