I have a canvas
element positioned absolutely over a Flash object of the same dimensions. I want to be able to click on the canvas
element and dispatch that event - or, more correctly, an imitation of that event - to the Flash object underneath.
I added an event listener to the Flash object so I know that the event is being successfully dispatched to the Flash object. The problem is that the Flash object simply doesn't react to it (e.g. clicking in the region of the giant 'play' button doesn't play the video).
Can Flash objects react to events in this fashion? Is there something special about Flash in the DOM that requires something other than JavaScript event delegation to activate responses from it?
Delegating click events from a DOM element to an underlying Flash object
Answer
Use ExternalInterface to communicate between your SWF and the DOM.
You can create a function inside your SWF and then call that ActionScript function from JS using:
ExternalInterface.call( functionInsideYourSWF )
In your case you would call your ActionScript function when someone clicks on your canvas element, then have Flash handle that click event internally with whatever you define inside your ActionScript function, e.g. play your video.
No comments:
Post a Comment