Replacement for flash.utils.Proxy

I’m trying to port an AS3 library to Haxe using OpenFL in order to ultimately convert it to JS. I was able to find OpenFL replacements for all the Flash API import statements except for two: flash.utils.Proxy and flash.utils.flash_proxy. I have done a fair amount of searching online and, so far, haven’t found any good solutions. When I ran AS3HX on the AS3 code, it converted

import flash.utils.flash_proxy;


import nme.utils.Proxy;

while it left

import flash.utils.Proxy;

unchanged. As far as I can tell, flash_proxy is just a namespace. Looking at the current github page for nme, it doesn’t look like the Proxy class exists anymore. So, even that doesn’t seem like an option.

These Proxy imports come up only one time in the library, but the class that they’re in is used in multiple other places, so I need to get this figured out somehow. The original AS3 source is here and my conversion of it to Haxe is here.

Any help on this would be very much appreciated. Thanks in advance!

That one looks tricky.

I never used flash.utils.Proxy, and by the look of it, it will not work in other environments. Move from Flash to C++ and it won’t work since it’s a static compiled language and not an interpreted runtime. However, I think this same class could be done as a Haxe abstract. This lets you override operators, so that you can customize how array access works, etc

It’s a bit lower-level and tricker, but I think you could likely reproduce the same general behavior (but strongly typed), here’s an example of the current openfl.Vector class, which works as an array, similar to this class seems to be:

Thanks for your input. I’m trying to figure out how important Proxy is to the functionality of this class. I found a different Haxe port of this library here (seemingly focused on the Haxe Flash target) and the author of that port just took out the Proxy import and all the override statements. I’ve contacted the author of the library to see if he’s willing to help me figure this out. I’ll post again if I get this figured out.

If I understand it, Proxy lets you change the array access behavior of an object dynamically. You can do a similar thing in Haxe (and a lot more) using the abstract type instead of Proxy on ActionScript 3. Another option would be to track down where this class is used, and then to handle how it is accessed, etc

Hi Colin

I originally created the WeightedArray class as a generic array with weights. I subsequently used it in Flint because I needed that functionality, but in Flint it does’t need to behave like an Array. So you can delete most of the class and it will still work.

I think you can reduce the class to just the constructor, add, remove, clear and getRandomValue methods, plus the Pair class, and Flint will still work. And with only those methods in the class there’s no need to extend Proxy or to use flash_proxy.

1 Like