使用flashDevelop嵌入Movieclip

时间:2010-02-07 05:15:02

标签: flex flash actionscript-3 actionscript

我正在尝试使用flashDevelop嵌入movieClip,但显然它无法正常工作,因为它无法识别其中的动画片段。这是我的代码

package com.objects{

    import flash.display.MovieClip
    import flash.text.TextField;
    import flash.events.*;
    import flash.text.TextFormat;

    [Embed(source='../../../lib/fighter.swf', symbol='InfoBox')] 
    public class InfoBox extends gameObject {

        protected var textf:TextField;
        protected var s:String;
        public var type:Boolean = false;
        private var letter:Number = 0;
        private var string:Array;
        private var line:Number = 0;
        private var portNum:Array;


        public function InfoBox():void
        {
            portNum = new Array();
            portrait.stop();
            x = 400;
            y = 550;

            string = new Array();
            var format = new TextFormat();
            format.size = 18;
            textf = new TextField();
            textf.width = 550;
            textf.height = 85;
            textf.x = -220;
            textf.y = -60;
            textf.wordWrap = true;
            textf.defaultTextFormat = format;
            addChild(textf);
            contButton.addEventListener(MouseEvent.MOUSE_DOWN, StoryNext);
        }

        private function StoryNext(e:MouseEvent):void
        {
            if(string.length > 1)
            {
                portNum.splice(0,1);
                string.splice(0,1);
                trace(string.length);
                letter = 0;
            }
            else
            {
                contButton.removeEventListener(MouseEvent.MOUSE_DOWN, StoryNext);
                dispatchEvent(new Event("StoryContinue"));
            }
        }

        public function textInfo(msg:String,num:Number = 1):void
        {
            string.push(msg);
            portNum.push(num);
        }

        override public function updateObject():void
        {
            TypeWords();

        }// End UpdateObject

        public function TypeWords():void
        {
            if(type)
            {
                portrait.gotoAndStop(portNum[0]);
                var s:String = string[0];               
                if(letter <= s.length)
                {
                    textf.text = s.substring(0,letter);
                }               
                letter++
            }
        }
    }
}

我收到此错误

C:\Users\numerical25\Documents\RealGames\FighterPilot\beta1FlashDev\src\com\objects\InfoBox.as(23): col: 4 Error: Access of undefined property portrait.

portrait是我在信息框影片剪辑中的影片剪辑。它已经在舞台上,我给它一个实例名称的肖像。它在flash中工作,但现在不在flashDevelop中

4 个答案:

答案 0 :(得分:2)

尝试按名称访问子项。它应该工作。

(getChildByName("portrait") as MovieClip).gotoAndStop(portNum[0]);

答案 1 :(得分:1)

您需要在类上定义相应的属性。在这种情况下,您可以添加:

public var portrait:MovieClip;

如果是其他类型,例如Sprite,您可以将定义更改为该类型。

编辑:如果您遇到问题setting up Flash Develop, I wrote some tutorials

答案 2 :(得分:1)

  

[嵌入(源= '.. / .. / .. / LIB / fighter.swf',   符号= '资讯盒')]

我会说使用SWC而不是SWF,它会使它更容易负载。

SWC保留所有内容,而swf可以删除不用于节省空间的资产。

同样在您的Flash开发面板中,您将看到swc(如swf)并查看所有包含的类。只需右键单击它并将其添加到库中。您不必使用[embed]代码。

首先尝试一下,除非你绝对需要一个swf。

要创建swc,请使用发布设置下的Flash选项卡。

答案 3 :(得分:0)

您可以为MovieClip添加链接名称并将其导出为SWC,假设名为“mymc” 然后将SWC文件复制到FD项目中。 在你的代码中,只需addChild(new mymc());