导入一个类并使其成为我游戏的一部分

时间:2009-09-04 18:05:11

标签: flash actionscript-3 class

大家好,我希望得到一些帮助,将这个课程输入到一个小游戏AS3

allowDomains:Array是允许域的列表

我的问题是如何编写此数组 以及放置它的地方所以都可以用Flash CS4编译。

以下课程。

package com.ikonicstudios.utils 
{
    import flash.display.DisplayObject;
    import flash.display.MovieClip;
    import flash.display.LoaderInfo;
    import flash.text.TextField;
    import flash.text.TextFormat;

    //rootLevel:MovieClip is the location of the root timeline
    //allowDomains:Array is a list of the allowed domains
    //will return true is the domain is allowed, false if the domain is not allowed
    //displayWarning dynamically adds a message across the screen

    public class SiteLock extends MovieClip
    {

        public var domain:String;
        public var rootLevel:DisplayObject;
        private var warningText:TextField = new TextField();

        public function SiteLock() 
        {
        }

        public function checkLock(rootLevel:DisplayObject, allowedDomains:Array):Boolean {
            this.rootLevel = rootLevel
            domain = rootLevel.loaderInfo.url;

            for each(var allowed in allowedDomains) {
                if (domain.indexOf(allowed)!=-1) {
                    return true;
                }
            }

            return false;
        }

        public function displayWarning() {  
            var sh = rootLevel.stage.stageHeight;
            var sw = rootLevel.stage.stageWidth;
            var format = new TextFormat("_sans", 14, 0x000000, true, false, false, null, null, "center");
            warningText.text = "This domain does not have permission to host this flash";
            warningText.y = sh / 2 ;
            warningText.width = sw;
            warningText.setTextFormat(format);
            warningText.selectable = false;
            rootLevel.stage.addChild(warningText);

        }

    }

}

使用Flash CS4时,类文件运行正常。但是当我尝试在Flex构建器中使用它时,我收到一些警告。见下文。任何人都知道如何删除此警告,并修复该类以在Flex生成器中工作。 ?谢谢约翰

  

1008:函数的返回值   'displayWarning'没有类型   宣言。第39行1008:变量   'allowed'没有类型声明。   第30行1008:变量'sh'没有   类型声明。第40行1008:   变量'sw'没有类型声明。   第41行1008:变量'format'具有   没有类型声明。第42行

1 个答案:

答案 0 :(得分:0)

var siteLock:SiteLock = new SiteLock()
if(!siteLock.checkLock(this, ["mydomain1.com","mydomain2.com"]))
    siteLock.displayWarning();

将其放在第0帧的脚本中。

I like this implementation of the concept better.