Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Anyone know the code to copy text?

Explorer ,
Oct 30, 2020 Oct 30, 2020

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

//Signature// I'm a creator. I love illustration, designing, animating , writing, voice overs, acting, making games .. Woo woo!
166
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2020 Oct 30, 2020

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2020 Oct 30, 2020

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/

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 02, 2020 Nov 02, 2020
LATEST

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

//Signature// I'm a creator. I love illustration, designing, animating , writing, voice overs, acting, making games .. Woo woo!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 02, 2020 Nov 02, 2020

Hi JoãoCésar,

 

Thanks for your reply! I will try it.

 

Line

//Signature// I'm a creator. I love illustration, designing, animating , writing, voice overs, acting, making games .. Woo woo!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines