0

我正在尝试开始使用名为 FlashDevelop 的 Flash IDE,它不使用我习惯的 .FLA 编辑器。我已经找到了如何将 /lib 文件夹中的文件嵌入到项目中,但我不确定如何像我之前所做的那样,将嵌入文件(例如 .jpg)与 .as 文件相关联以提供说明关于如何行动。下面是代表我尝试弄清楚的代码,在此先感谢您的帮助。

package 
{
    import flash.display.Bitmap;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;

    [Frame(factoryClass="Preloader")] //This references an auto generated preloader which I haven't touched
    public class Main extends Sprite 
    {
        [Embed(source="../lib/index.jpg")]
        public var logo:Class; //I'm attempting to connect the image in the above line to my logo.as file, all that's in there is an empty constructor and a simple update method that moves the image to the right
        public var pic:logo;

        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            // entry point
            pic:logo = new logo();
            addChild(pic);
            addEventListener(Event.ENTER_FRAME, update);
        }

        private function update(e:Event):void 
        {
            pic.update();
        }



    }

}
4

1 回答 1

1

您可以简单地将 index.jpg 嵌入和实例化移动到logo.as中。(另外,如果你坚持用大写字母命名你的类,它可以帮助避免类和变量之间的混淆,所以例如我会称之为Logo.as。)然后你的主类只需要添加 anew Logo()Logo.as将注意创建实际图像。

编辑:另外,请确保您不会偶然这样做:

pic:Logo = new Logo();

那应该是:

pic = new Logo();
于 2013-01-19T21:32:21.687 回答