首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >导入了一个类并使它成为我游戏的一部分

导入了一个类并使它成为我游戏的一部分
EN

Stack Overflow用户
提问于 2009-09-04 18:05:11
回答 1查看 305关注 0票数 0

你好,我希望能得到一些帮助,把这个类移植到一个小游戏AS3中。

数组是允许的域列表。

我的问题是如何编写这个数组,以及将它放在哪里,以便所有这些都可以用Flash编译。

下课。

代码语言:javascript
复制
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);

        }

    }

}

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

1008:函数'displayWarning‘的返回值没有类型声明。第39 1008行:变量“允许”没有类型声明。第301008行:变量'sh‘没有类型声明。第40行1008:变量'sw‘没有类型声明。第41 1008行:变量“format”没有类型声明。第42项

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-09-04 18:22:27

代码语言:javascript
复制
var siteLock:SiteLock = new SiteLock()
if(!siteLock.checkLock(this, ["mydomain1.com","mydomain2.com"]))
    siteLock.displayWarning();

将其放在框架0的脚本中。

我更喜欢这个概念的实施。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1380726

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档