6

My AIR app is loading an SWF file which contains a text field for input. I can type into the text field but copying and pasting is broken. When I try to paste something using the keyboard shortcut, the text field becomes like this:

enter image description here

(this is not a "T").

And after a series of copy/pasting it looks like this:

enter image description here

When I do a right-click on the text field, nothing happens, no context menu with copy/paste options appears.

The SWF that is being loaded is in AS2 (it's practically impossible to port it to AS3 because the code in it is very vast and sophisticated). I can't replace that SWF, it has extremely high value for my project. Apart from this trouble, the SWF works fine. Maybe I could change some config constants in the AS3 settings of the loader?

For testing purposes, I created two .flas, one is in AS2 and contains a text field and the other is in AS3 and loads the text field. You can download the .flas in an archive from here.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Pleo
  • 309
  • 1
  • 11
  • THere is no AS2-AS3 communication maybe this affects you? Have you tried with a sample SWF (AS3) loaded in place the other SWF and tested this copy and paste issue? – Lukasz 'Severiaan' Grela Apr 02 '13 at 15:13
  • @Lukasz'Severiaan'Grela Inter-SWF communication has nothing to do with it. You can ascertain this from the two .flas I attached. – Pleo Apr 02 '13 at 15:21

1 Answers1

6

It's dirty hack, but it works. :) Convert your SWF from AVM1 to AVM2 "on fly". Use ForcibleLoader https://code.google.com/p/as3-classes/source/browse/trunk/org/lzyy/util/ForcibleLoader.as

In loader.fla:

var loader:Loader = Loader(addChild(new Loader()));
var fLoader:ForcibleLoader = new ForcibleLoader(loader);
fLoader.load(new URLRequest('tf.swf'));

In ForcibleLoader.as add import flash.system.LoaderContext;

and

var lc:LoaderContext = new LoaderContext();
lc.allowCodeImport = true;
loader.loadBytes(inputBytes, lc);

instead

loader.loadBytes(inputBytes);

in line ~75

Smolniy
  • 456
  • 3
  • 9
  • This is hands down awesome! You made my day, sir! Thank you so much! Gonna research more on the AVM1/AVM2 topic now. – Pleo Apr 02 '13 at 18:43
  • Ah snap! I've just checked it with the actual SWF and although it loads all the graphics, it does not run any code from the loaded SWF! :( What have I missed? – Pleo Apr 03 '13 at 08:50
  • If you put an instance name on the text field in the AS2 .fla, e.g. `tf`, and add ActionScript to the first frame like `tf.text = "Hello";` it will work in the AS2 but not in the AS3! Help. – Pleo Apr 03 '13 at 10:43
  • Bad news :( Don't know... (btw: Shift-Insert pastes as expected) – Smolniy Apr 03 '13 at 15:21