Skip to main content
sinious
Legend
October 24, 2012
Question

LocationChangeEvent anomalies, not firing via JavaScript?

  • October 24, 2012
  • 3 replies
  • 4049 views

Hey all,

Has anyone noticed LocationChangeEvent doesn't appear to fire when using JavaScript? The StageWebView.locationChanging documentation specifies it will be called:

A locationChanging event is only dispatched when the location change is initiated through HTML content or code running inside the StageWebView object,such as when a user clicks a link.

I'm changing the location via JavaScript and only if I've clicked an anchor (<a>) link will this actually fire off correctly. I'm assigning it simply to a button:

<input type="button" value="Click" onclick="location.href = 'http://www.example.com';"/>

The event never fires off.

I'm filling my StageWebView with custom content loaded via loadString() (which doesn't fire off that event). If someone clicks any link I've provided I want to bounce them out to a full browser. I'm trying to preventDefault() so the StageWebView does not load the content while running a navigateToURL() so it opens in Safari (this is an iPad app). Works great for anchors, just not in that quick JavaScript example.

Anyone else notice this behavior?

This topic has been closed for replies.

3 replies

Inspiring
May 13, 2019

Hello all.

I am having the same issue on AIR32.0.0.103 on Desktop.

LOCATION_CHANGING is not fired, therefore I cannot preventDefault();

On iOS same code works, so it is a Desktop issue.

Did you find a fix for this?

cheers

Pippo

Participating Frequently
November 8, 2012

Yes, htmlLoader is an object of type window.runtime.flash.html.HTMLLoader.  http://help.adobe.com/en_US/air/reference/html/flash/html/HTMLLoader.html

Here is the excerpt from the doc regarding locationChanging events:

locationChanging

Event

Event Object Type: flash.events.LocationChangeEvent

property LocationChangeEvent.type  =  flash.events.LocationChangeEvent.LOCATION_CHANGING

Runtime Versions: 2.7

  Signals that the location property of the HTMLLoader object is about to change.  

A locationChanging event is only dispatched when the location change is initiated through  HTML content or code running inside the HTMLLoader object,such as when a user clicks a link.  By default, the new location is displayed in this  HTMLLoader object. You can call the preventDefault() method of the event  object to cancel the default behavior. For example, you could use the flash.net.navigateToURL()  function to open the page in the system browser based on the location  property of the event object

A locationChanging() is not dispatched when you call the following methods:

  • load()
  • loadString()
  • reload()
  • historyBack()
  • historyForward()
  • historyGo()

  In addition, this event is not dispatched when the destination page is opened in the system browser, since  the HTMLLoader location does not change.      Dispatched before a location change that is initiated via the content displayed  in an HTMLLoader or StageWebView object.   

Call the preventDefault() method of the event object to prevent the change.

A locationChanging event is not dispatched when you change the location with the following methods:

  • historyBack()
  • historyForward()
  • historyGo()
  • load()
  • loadString()
  • loadURL()
  • reload()

HTMLLoader objects dispatch locationChanging events in AIR 2.7 and later.

sinious
siniousAuthor
Legend
November 8, 2012

Ah you're coming from creating applications via HTML. That's a whole concept I never toyed with. I just use flash/flex to develop flash/flex. Flash and Flex don't mix. You do one or the other because they run on different layers, as much as Stage3D or StageVideo do compared to the Flash display list. I can be wrong but despite it saying it runs on the Flash AS3 display list, It looks like what you're doing is in a whole different category. I'm not sure mobile applications are applicable there.

That is indeed a whole different HTMLLoader class, much more functional. I'm not a fan of it having a similar name and seemingly similar package name although being entirely different but that's what it is. Interesting to know its locationChanging event is also failing in a similar way. Perhaps similar concepts to invoking an OS browser could be used, causing the same behavior.

Legend
November 8, 2012

BTW, sinious, I don't think you _need_ to preventDefault(); to prevent the load - LOCATION_CHANGE seems to fire early enough in the flow that you can just reload your string when LOCATION_CHANGE fires - before any requests are made.

G

Participating Frequently
November 7, 2012

I am having a similar issue in a Air Desktop (windows) application.  The LOCATION_CHANGING event listener is registered, but doesn't fire even thought the willTrigger property is TRUE.

htmlLoader.addEventListener(window.runtime.flash.events.LocationChangeEvent.LOCATION_CHANGING, function(event){DebugFunction("LocationChangeEvent.LOCATION_CHANGING");});

Legend
November 8, 2012

Yes, I've noticed that too.

LOCATION_CHANGE will always fire but LOCATION_CHANGING only fires with a simple HTML link.

G

sinious
siniousAuthor
Legend
November 8, 2012

Andy~ Are you using a HTMLLoader? I'm talking about a StageWebView. I see there's an event on a HTMLLoader for locationChange but not LOCATION_CHANGING. Unless you just named your object the same as the HTMLLoader class.

Gaius~ Thanks for the confirmation. I suspected this bugger wasn't firing off properly. I always get LOCATION_CHANGE but seldomly a LOCATION_CHANGING will fail.

I had to buy the UIWebView ANE just to convert all links to JavaScript and JS->AS3 the location change to assure this event was not missed. Now I get it every time. Well worth the money IMHO (for many reasons).