Type was not found or was not a compile-time constant?

I don't understand what is wrong with my code. When I debug it tells me: 1046: Type was not found or was not a compile-time constant: LocationChangeEvent. This is the code:

// 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);

Is there a way to change this code to make it work, or this code can't be used any longer?

Answers


According to the reference, LocationChangeEvent should indeed be in flash.events if compiled in AS3. I'm not sure why it's not found.

Try compiling a simpler example:

import flash.events.LocationChangeEvent;
var ev:LocationChangeEvent;

Need Your Help

JQGrid Showing empty while processing more than 3200 records with MVC 4

asp.net-mvc-4 c#-4.0 razor jqgrid mvcjqgrid

JQGrid is working fine for records up to 3000 and so with loadone:true , while it comes to more than 3200 it is showing empty grid. I would like to take up with server side paging and loadonce:fals...

Trying to print multiple files from directory

python

I'm trying to print multiple files in a list from my directory.