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

Adobe Animate HTML 5 Error when accessing internal library via external js script

New Here ,
Aug 24, 2023 Aug 24, 2023

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

 

let myBlue = new lib.blueShape;
exportRoot.addChild(myBlue);
let xPosition = Math.floor(Math.random()*700);
let yPosition = Math.floor(Math.random()*700);
myBlue.x = xPosition;
myBlue.y = yPosition;
root.push(myBlue);

 throws an error on - let myBlue = new lib.blueShape;

 

1.jpgexpand image

1.3K
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 2 Correct answers

Community Expert , Aug 25, 2023 Aug 25, 2023

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);

Translate
Community Expert , Aug 25, 2023 Aug 25, 2023

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);

Translate
New Here ,
Aug 27, 2023 Aug 27, 2023

Thank you very much! You are the best, I figured out how to add features to clips, thanks again! and sorry for disturbing

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 ,
Aug 27, 2023 Aug 27, 2023

you're welcome, but i'm not sure how we got from the last post about problem to your most recent one with a solution.

 

what code are you using?

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 ,
Aug 27, 2023 Aug 27, 2023

Here is the code 

var list_platforms = new Array();
init.bind(this)(); 
function init(){
for(var i = 0; i < this.numChildren; i++) {
console.log(getMCSymbolPrototype(this.getChildAt(i)).constructor);
list_platforms.push(this.getChildAt(i))
console.log(list_platforms.length)
}
 
}
 
 
for (let i =0; i < list_platforms.length; i++){
 
    list_platforms[i].addEventListener("click", function () {
list_platforms[i].visible = false
 
})
}
Only here is the problem, when I add frames in the movie clip, for example, so that the square turns red, it gives an error
1.jpgexpand image
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 ,
Aug 27, 2023 Aug 27, 2023

All the same, I need help, when I click hide an object, it hides all the objects that are on the canvas, but I need to individually

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 ,
Aug 27, 2023 Aug 27, 2023

is the code you're showing in an external js file?

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 ,
Aug 27, 2023 Aug 27, 2023

 Yes, the internal code created another movie clip, the error was removed, well, I can’t understand how I can make functions for each individually, for example, the blue square disappears when you click it, but the green square doesn’t, since all movie clips disappear

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 ,
Aug 27, 2023 Aug 27, 2023

get rid of the getMCSymbol... code. you're not using it.

 

and use "this" in your event listener.

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 ,
Aug 27, 2023 Aug 27, 2023

What does it look like?

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 ,
Aug 28, 2023 Aug 28, 2023

 Whatever I haven’t written already, I can’t individually access the library, it adds all the movie clips from the canvas to the array and makes them under one function

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 ,
Aug 28, 2023 Aug 28, 2023
var list_platforms = new Array();
init.bind(this)(); 
function init(){
for(var i = 0; i < this.numChildren; i++) {
// still selecting all children.  again, i don't know how to select ones with a particular linkage id
list_platforms.push(this.getChildAt(i))
console.log(list_platforms.length)
}
 
}
 
 
for (let i =0; i < list_platforms.length; i++){
 
    list_platforms[i].addEventListener("click", function (e) {
e.target.visible = false
 
})
}
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 ,
Aug 28, 2023 Aug 28, 2023

 And I don't understand how to address each object individually

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 ,
Aug 28, 2023 Aug 28, 2023

the objects in list_playforms?

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 ,
Aug 28, 2023 Aug 28, 2023

 No, this is an array, well, when I add list_platforms.push(this.getChildAt(i)) then everything on the canvas is added to this array, but it is necessary that this array be individual, now I will write an example from as3.0, there it is works

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 ,
Aug 28, 2023 Aug 28, 2023

if you're trying to select instances with a particular linkage, this has been addressed.

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 ,
Aug 28, 2023 Aug 28, 2023

So what should be the code?

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 ,
Aug 28, 2023 Aug 28, 2023
var list_platforms: Array = new Array();
var list_coins: Array = new Array(); 
 
var list_enemies: Array = new Array();
init();
function enter_frame ( e: Event ) : void {
for ( var i : int = 0; i < list_platforms.length; i++ ) {
 
    var platform: MovieClip = list_platforms[ i ];
  
    if (platform.moving){
      platform.y += platform.sp;
 
      if (char.platform == platform){
        char.y += platform.sp;
      }
 
      if (platform.y>=platform.start_y+50 || platform.y<=platform.start_y-50){
        platform.sp=platform.sp*-1;
  }
}
}
 
function init(){
  for (var i:uint = 0; i < numChildren; i++){
    if (getChildAt(i) is Platform){
      list_platforms.push(getChildAt(i));
    }
 
    if (getChildAt(i) is Coin){
      list_coins.push(getChildAt(i));
    }
 
    if (getChildAt(i) is Enemy){
      list_enemies.push(getChildAt(i));
    }
  }
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 ,
Aug 28, 2023 Aug 28, 2023

all the is-statements in init() are problematic. i gave you a starting point to solve this, but i don't know how to proceed.  ie, i would have to spend significant time to answer that.

 

there's only a certain amount of time i'll devote to solving user coding problems in the forums. beyond that, i would need to be hired (for pay).

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 ,
Aug 29, 2023 Aug 29, 2023

 I understand you, thank you very much

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 ,
Aug 29, 2023 Aug 29, 2023
LATEST

you're welcome.

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