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

Canvas Global Scripts

New Here ,
Sep 24, 2018 Sep 24, 2018

I'm new to Canvas in Animate. I have the basics down I think, but I'm having trouble with Global scripting. It may be that I'm thinking of the Global Scripts window incorrectly, but my thought was that it can be used to write code that will be accessed throughout the project. My hope was to use it to declare global variables and functions that I want to later call on other frames in the file. However, I can't seem to get any of my variables to recognize between the global script window and other frames. I was trying to learn how to use this window, but found the tutorials a little lacking. The help files didn't help me understand it any better either. Could someone help me understand what type of code can be used in the Global Scripts window? I saw on one site the use of console. This got me thinking only strict JS could be used. But I couldn't even declare variables there. Any help or advice would be greatly appreciated! Thanks everyone in advanced!

2.6K
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

correct answers 1 Correct answer

Community Expert , Oct 09, 2018 Oct 09, 2018

you can't target on-stage objects with a global script until the object exists.  otherwise, there's no problem.

eg, if you wanted to do something with objects in frame 33 using a global script, on frame 33 use something like:

frame33_globalF.bind(this)();

in your global script:

function frame33_globalF(){

// you can reference frame 33 objects here

}

Translate
Community Expert ,
Sep 25, 2018 Sep 25, 2018
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
New Here ,
Oct 09, 2018 Oct 09, 2018

kglad,

Thank you, but I started there and it was very limited on formatting and object targeting. I usually start with the AdobeX files before hitting the forums. I appreciate the advice though. Thank you.

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 09, 2018 Oct 09, 2018

you can't target on-stage objects with a global script until the object exists.  otherwise, there's no problem.

eg, if you wanted to do something with objects in frame 33 using a global script, on frame 33 use something like:

frame33_globalF.bind(this)();

in your global script:

function frame33_globalF(){

// you can reference frame 33 objects here

}

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 ,
Sep 25, 2018 Sep 25, 2018

You should post what you've attempted. I just tried it and it worked fine. I put this code in the Global Script window:

var bob = "your uncle";

function mytest() {

    alert("success!");

}

Then this script in the first frame of the root timeline:

alert(bob);

mytest();

And got two popups with the expected content when I ran the page.

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
New Here ,
Oct 09, 2018 Oct 09, 2018

Thanks for the response Clay,

I tried that, and a little more elaborate versions of it but couldn't get it to work. Specifically, I tried to target objects on the stage but I just get blank pages.

For example, I wanted to globally assign the "this" object to the variable "_this" because some of my code on the frames worked only when I used this variable instead of just saying something like "this.objectname.visible=false;", where objectname is the name of the object on the screen. But when I did this, none of the code worked. I just got a blank screen. Is there a proper way to target objects from the global scripts window that I'm missing?

Thank you in advanced!

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 09, 2018 Oct 09, 2018
LATEST

prashantsavalia  wrote

For example, I wanted to globally assign the "this" object to the variable "_this" because some of my code on the frames worked only when I used this variable instead of just saying something like "this.objectname.visible=false;", where objectname is the name of the object on the screen. But when I did this, none of the code worked. I just got a blank screen.

The global variable exportRoot is automatically created by Animate and points to the root timeline.

When you get a white screen, 99% of the time that means there was a runtime error. Open the browser's developer console and view the error message.

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