你好,我希望能得到一些帮助,把这个类移植到一个小游戏AS3中。
数组是允许的域列表。
我的问题是如何编写这个数组,以及将它放在哪里,以便所有这些都可以用Flash编译。
下课。
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项
发布于 2009-09-04 18:22:27
var siteLock:SiteLock = new SiteLock()
if(!siteLock.checkLock(this, ["mydomain1.com","mydomain2.com"]))
siteLock.displayWarning();将其放在框架0的脚本中。
我更喜欢这个概念的实施。
https://stackoverflow.com/questions/1380726
复制相似问题