开发者

What I might be doing wrong in this code?

I am relatively new to flash. I am trying to create a square grid and add it to the movie. When I open the actionscript panel by pressing F9 and when I type the following code,

var square:SquareClip = new SquareClip();
addChild(square);

Things are working fine (the squareclip is appearing in the movie).

Instead when I do this however, I deleted the above code and just create a new instance of Main,

new Main

and inside Main.as

package{
    //----
    //IMPORT
    //
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;

    //Class creation
    public class Main extends MovieClip {
        //PROPERTIES

        public function Main():void {           
            layout_in_grid();
        }

        private function layout_in_grid():void{
            trace("layout_in_grid");

            //create a new Square
            var square:SquareClip = new SquareClip();
            addChild(square);

            trace("S开发者_如何学JAVAquare added");
        }
    }
}

And when I run the code, my square is not coming. I am doing something wrong very basically. Please help me.


You need to add Main to the displaylist:

var myMain : Main = new Main();
addChild(myMain);

You could also set Main as your document class.


@Mattias is correct. But you should set this as the Document Class as he suggested - When you've selected the stage, in the properties there will be an input box allowing you to enter the name of the class.

If your file is in the same location as the FLA and called 'Main.as' you enter in the box:

Main

If the file is within a folder structure e.g. com/company/projects/Main.as - enter:

com.company.projects.Main

--

Kudos on learning the OOP way!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜