Copy link to clipboard
Copied
Recently started learning Javascript and here is the problem When trying to access the internal Adobe Animate library through an external JS script, it swears and writes an error And if I write this script inside Adobe Animate it works fine, please help
throws an error on - let myBlue = new lib.blueShape;
2 Correct answers
1. remove your js file from the include panel
2. use code to reference your library (and you'll need the main timeline, too)
3. load your js with code
// don't use "var"
tl = this; // main timeline reference
LIB = lib; // library reference
// load your js file(s)
var queue = new createjs.LoadQueue();
queue.loadManifest([
"ext_file.js"
]);
in ext_file.js you can use:
let myBlue=new LIB.blueShape();
tl.addChild(myBlue);
i showed you how to do that
in your fla
// don't use "var"
tl = this; // main timeline reference
LIB = lib; // library reference
// load your js file(s)
var queue = new createjs.LoadQueue();
queue.loadManifest([
"ext_file.js"
]);
in your external js file
let myBlue=new LIB.blueShape();
tl.addChild(myBlue);
Copy link to clipboard
Copied
you have to wait until the library is initialized to access it.
and that should be
new lib.blueShape();
Copy link to clipboard
Copied
Thanks for the reply, but it still gives the same error.
Copy link to clipboard
Copied
you still have a timing issue. and then you'll need a lib reference.
Copy link to clipboard
Copied
Sorry for my bad English, maybe I don't understand something, how can I write a script correctly?
Copy link to clipboard
Copied
1. remove your js file from the include panel
2. use code to reference your library (and you'll need the main timeline, too)
3. load your js with code
// don't use "var"
tl = this; // main timeline reference
LIB = lib; // library reference
// load your js file(s)
var queue = new createjs.LoadQueue();
queue.loadManifest([
"ext_file.js"
]);
in ext_file.js you can use:
let myBlue=new LIB.blueShape();
tl.addChild(myBlue);
Copy link to clipboard
Copied
var queue = new createjs.LoadQueue(); queue.loadManifest([ "ext_file.js" ]); This is how I add the code well, I need something from the ext_file.js file to access the Adobe Animate library, and not from the timeline
Copy link to clipboard
Copied
i showed you how to do that
in your fla
// don't use "var"
tl = this; // main timeline reference
LIB = lib; // library reference
// load your js file(s)
var queue = new createjs.LoadQueue();
queue.loadManifest([
"ext_file.js"
]);
in your external js file
let myBlue=new LIB.blueShape();
tl.addChild(myBlue);
Copy link to clipboard
Copied
It's my fault, everything works, thank you very much!
Copy link to clipboard
Copied
you're welcome
Copy link to clipboard
Copied
Sorry for another question, although it is not on the local topic. Here's how to make an object from the scene added to an array, so that my platforms would have the same properties, so that I would not write each platform separately in actionscrip 3.0 it looked like this
var list_platforms: Array = new Array();
init();
function init(){
for (var i:uint = 0; i < numChildren; i++){
if (getChildAt(i) is Platform){
list_platforms.push(getChildAt(i));
}
how will it look like in js?
Copy link to clipboard
Copied
are you trying to find the linkage id of objects, or how to use arrays?
Copy link to clipboard
Copied
I want to copy movie clips on the canvas, for example platforms, so that they would be under the same name and that they would have one property, so that I wouldn’t call each platform like platform 1, platform 2 and so on, of course you can’t understand what I want to explain
Copy link to clipboard
Copied
you're still talking about html5/canvas, correct?
is Platform a linkage id and you're trying to find instances with that linkage id?
Copy link to clipboard
Copied
Yes, on actionscrip 3.0 the script looked like this
var list_platforms: Array = new Array();
init();
function init(){
for (var i:uint = 0; i < numChildren; i++){
if (getChildAt(i) is Platform){
list_platforms.push(getChildAt(i));
}
On js, I don’t know how it is written, the script indicates that when copying the platform, it automatically adds to the array, thereby one name from the library for all copied objects
Copy link to clipboard
Copied
you can find the linkage name using the following, but how to compare that to something needs more work:
getMCSymbolPrototype(this.getChildAt(i)).constructor
Copy link to clipboard
Copied
I suspected that through the constructor, well, what does the script look like in full?
Copy link to clipboard
Copied
init();
function init(){
for (var i = 0; i < numChildren; i++){
console.log(getMCSymbolPrototype(this.getChildAt(i)).constructor);
}
Copy link to clipboard
Copied
I can’t understand this script, I will try to do something, thanks for the answer, I won’t bother you
Copy link to clipboard
Copied
use the script and open the developer console when testing.
Copy link to clipboard
Copied
Yes, I do that, but it gives an error in the console
Copy link to clipboard
Copied
what error?
Copy link to clipboard
Copied
I don’t understand why I had an error, I didn’t write the way you wrote to me the first time, now it displays to me without an error, well, I don’t understand how I can add a property now, well, for example, so that when you click the mouse they disappear
Copy link to clipboard
Copied
you're trying to add a property to what?
Copy link to clipboard
Copied
Here to these objects in the C_link library so that they have one function, for example, these are coins, when pressed, they disappear


-
- 1
- 2