Actionscript 3 找不到类型或类型不是编译时常量?
我不明白我的代码出了什么问题。调试时,它告诉我:1046:Type未找到或不是编译时常量:LocationChangeEvent。代码如下:Actionscript 3 找不到类型或类型不是编译时常量?,actionscript-3,flash,Actionscript 3,Flash,我不明白我的代码出了什么问题。调试时,它告诉我:1046:Type未找到或不是编译时常量:LocationChangeEvent。代码如下: // imports import flash.events.Event; import flash.events.LocationChangeEvent; import flash.geom.Rectangle; import flash.media.StageWebView; import flash.net.navigateToURL; import
// imports
import flash.events.Event;
import flash.events.LocationChangeEvent;
import flash.geom.Rectangle;
import flash.media.StageWebView;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.events.MouseEvent;
// setup variables
var _stageWebView:StageWebView;
var myAdvertURL:String = "http://terrypaton.com/ads/exampleAdvert.html";
//
function createAd(event:MouseEvent):void {
// check that _stageWebView doersn't exist
if (! _stageWebView) {
_stageWebView = new StageWebView () ;
// set the size of the html 'window'
_stageWebView.viewPort = new Rectangle(0,0,480,80);
// add a listener for when the content of the StageWebView changes
_stageWebView.addEventListener(LocationChangeEvent.LOCATION_CHANGE,onLocationChange);
// start loading the URL;
_stageWebView.loadURL(myAdvertURL);
}
// show the ad by setting it's stage property;
_stageWebView.stage = stage;
}
function toggleAd(event:MouseEvent):void {
trace("toggling advert",_stageWebView);
// check that StageWebView instance exists
if (_stageWebView) {
trace("_stageWebView.stage:"+_stageWebView.stage);
if (_stageWebView.stage == null) {
//show the ad by setting the stage parameter
_stageWebView.stage = stage;
} else {
// hide the ad by nulling the stage parameter
_stageWebView.stage = null;
}
} else {
// ad StageWebView doesn't exist - show create it
createAd(null);
}
}
function destroyAd(event:MouseEvent):void {
// check that the instace of StageWebView exists
if (_stageWebView) {
trace("removing advert");
// destroys the ad
_stageWebView.stage = null;
_stageWebView = null;
}
}
function onLocationChange(event:LocationChangeEvent):void {
// check that it's not our ad URL loading
if (_stageWebView.location != myAdvertURL) {
// destroy the ad as the user has kindly clicked on my ad
destroyAd(null);
// Launch a normal browser window with the captured URL;
navigateToURL( new URLRequest( event.location ) );
}
}
// setup button listeners
createAdBtn.addEventListener(MouseEvent.CLICK,createAd);
toggleAdBtn.addEventListener(MouseEvent.CLICK,toggleAd);
destroyAdBtn.addEventListener(MouseEvent.CLICK,destroyAd);
是否有办法更改此代码以使其正常工作,或者此代码不能再使用?根据参考资料,如果在AS3中编译,LocationChangeEvent确实应该在flash.events中。我不知道为什么找不到 尝试编译一个更简单的示例:
import flash.events.LocationChangeEvent;
var ev:LocationChangeEvent;
由于某些原因,仍然找不到它。参考资料说:语言版本:ActionScript 3.0运行时版本:AIR 2.5。尝试使用编译器设置进行试验。一定有版本不匹配的问题。我相信LocationChangeEvent是特定于AIR的类。您是作为AIR应用程序发布,还是发布到SWF?