Pasting into input text in HTML5 target



  • Hi all,

    Looking here :
    Re: Copy/Pasting strings to/from clipboard on HTML5 target

    And trying to implement I have no success in get data from the clipboard into an FlxInputText.

    As the post is quite old, has anybody some hints / piece of code to share ?

    Cheers.
    Bruno



  • Ok after loosing hairs with openfl or lime api and being unsuccesfull.
    Here is a pure html5 workaround (for some that would stumble upon this post)

    // some were in your state initialisation
    var myInput = new FlxUIInputText();
    
    #if js
    //import js.Browser;
    //import js.html.Clipboard;
    //import js.html.ClipboardEvent;
    Browser.document.addEventListener("copy", onCopy);
    Browser.document.addEventListener("paste", onPaste);
    #elseif flash
    //Use Clipboard.generalClipboard
    #end
    add( myInput );
    

    then the listeners

    function onPaste(e: ClipboardEvent):Void 
    {
        myInput.text = e.clipboardData.getData("text/plain");
    }
    function onCopy(e: ClipboardEvent):Void 
    {
        Browser.navigator.clipboard.writeText(myInput.text);
    }
    

Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.