Copy link to clipboard
Copied
I want to put a special code in my game and if you click a button, it will copy the text to your memory.
Do you know what the script is to do that?
Thanks ahead,
Line
Copy link to clipboard
Copied
Hi.
Supposing you have a button in the main timeline (called yourButton) created with Animate's drawing and design tools and a TextInput component instance called yourInput, the code could be something like this:
this.yourButton.on("click", function(e)
{
var input = document.getElementById("yourInput");
input.select();
document.execCommand("copy");
});
I hope it helps.
Regards,
JC
Copy link to clipboard
Copied
Per the MDN page on document.execCommand(), "This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it."
The modern way to copy to the clipboard is using the clipboard API. However, IE11 doesn't support this. A properly robust solution would be to check for the clipboard API and use that if available. If it's not available, check for and use execCommand. If that's not available, do nothing.
https://flaviocopes.com/clipboard-api/
Copy link to clipboard
Copied
Thanks ClayUUID,
I appreciate your constant attention!
In regards to what JoãoCésar wrote, is that included? I'm surprised to read that the feature is obsolete.. i feel like being able to copy some text. like a coupon code or a password.. or something you just wouldn't want to have to type out, would be a capability people would want to work. Click here to copy.. I've seen it so many times on sites.. Is everyone just using it until it's removed everywhere?
With me thinking that.. I wonder if my initial inquiry was written incorrectly and I am misunderstood..
My game is a canvas game for phone/desktop play.. I just want some text to be saved to memory as if it were something you'd manually highlight and copy to paste somewhere else .
Thanks again,
Line
Line
Copy link to clipboard
Copied
Hi JoãoCésar,
Thanks for your reply! I will try it.
Line