Я не понимаю, что не так с моим кодом. Когда я его отлаживаю, он говорит мне: 1046: Тип не был найден или не был константой времени компиляции: LocationChangeEvent. Это код:Тип не был найден или не был константой времени компиляции?
// 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);
Есть ли способ изменить этот код, чтобы заставить его работать, или этот код не может использоваться больше?
Я считаю, что 'LocationChangeEvent' является классом AIR-специфичны. Вы публикуете приложение AIR или SWF? – IQAndreas