Does "" only work for Flash targets?

I have a project that uses a single EventListener to intercept all Mouse clicks and react accordingly based on “”. This works fine for Flash targets, but throws an error of “ has no field name” on HTML5 and Windows targets. Is this behaviour expected, does “” only work for Flash targets?

The code below works in Flash but not HTML5 or Windows


import openfl.display.Sprite;
import openfl.Lib;

class Main extends Sprite 

	var red = new Sprite();
	public function new() 
		super();;, 0, 100, 100);; = "SpriteOne";
		stage.addEventListener(MouseEvent.CLICK, handleMouse);
	function handleMouse( event:MouseEvent )
		 trace (;


This is my first experience using any of the technologies associated with OpenFL, so I may be overlooking something fundamental.

Many thanks in advance.

You should use casting:

var myButton:Sprite = cast(,Sprite);

Thank you so much for your help, that did the trick. used to be Dynamic, but this broke getter/setter support, and hurt performance on static platforms. Sorry about the inconvenience :slight_smile:

So I used to be able to do something like this:

private function onURLloaderComplete(e:Event){
		trace("onURLloaderComplete result:";

to what do I have to cast the target now in order to access .data?

Haxe getters/setters are a compile-time feature. if you do something like:

 var target:Dynamic = mySprite;
target.x = 100;

… it won’t work correctly. It will try and change an x field directly, but at compile-time, Haxe replaces references to Sprites to the setter similar to:

target.set_x (100);

Because of this problem, letting be Dynamic causes problems for many kinds of problems.

Use cast(, URLLoader);, var urlLoader:URLLoader = cast; or use a reference to your loader you may have saved elsewhere and it should work great :slight_smile:

I’m still not really getting it. I understand I need to cast it and I did, but then I need to access the data property of the loader and that’s empty. What I am doing wrong?

private function onURLloaderComplete(e:Event){
		var loader:URLLoader=cast(, URLLoader);
	trace("result:"+loader+" data:";

result:[object URLLoader] data:

Is it a URLLoader, or Loader (with contentLoaderInfo)

Is it the string format type, or ByteArray?

Perhaps check if the response is null, and if not, what length it is

var byteArray:ByteArray =;

might also be helpful, to be sure the dynamic data is cast correctly (or similarly with a String type)