Unable to do copy/paste on textfields in loaded SWFs in AIR
Asked Answered
V

1

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.

Verso answered 2/4, 2013 at 13:59 Comment(2)
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?Surprising
@Lukasz'Severiaan'Grela Inter-SWF communication has nothing to do with it. You can ascertain this from the two .flas I attached.Verso
R
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

Rubino answered 2/4, 2013 at 18:21 Comment(4)
This is hands down awesome! You made my day, sir! Thank you so much! Gonna research more on the AVM1/AVM2 topic now.Verso
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?Verso
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.Verso
Bad news :( Don't know... (btw: Shift-Insert pastes as expected)Rubino

© 2022 - 2024 — McMap. All rights reserved.