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

assigning names from a class adobe animate/html5/easelJS

Participant ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

Hi team,

So I think I got my index.html and game.js file connected successfully

- here is some code from an easelJS tutorial to get a moving red circle- this code is in my game.js file and the circle works fine.

class Game{
    constructor(exportRoot, stage){
        this.root = exportRoot;
        this.stage = stage;
        this.init();
    }
    
    init(){
        const game = this;

        var circle = new createjs.Shape();
        circle.graphics.beginFill("Crimson").drawCircle(0, 0, 50);
        circle.x = 100;
        circle.y = 100;
        stage.addChild(circle);
        createjs.Tween.get(circle, {loop: true})
          .to({x: 400}, 1000, createjs.Ease.getPowInOut(4))
          .to({alpha: 0, y: 75}, 500, createjs.Ease.getPowInOut(2))
          .to({alpha: 0, y: 125}, 100)
          .to({alpha: 1, y: 100}, 500, createjs.Ease.getPowInOut(2))
          .to({x: 100}, 800, createjs.Ease.getPowInOut(2));
        createjs.Ticker.setFPS(60);
        createjs.Ticker.addEventListener("tick", stage);
      }
}

Here is the index.html

<!DOCTYPE html>
<!--
	NOTES:
	1. All tokens are represented by '$' sign in the template.
	2. You can write your code only wherever mentioned.
	3. All occurrences of existing tokens will be replaced by their appropriate values.
	4. Blank lines will be removed automatically.
	5. Remove unnecessary comments before creating your template.
-->
<html>
<head>
<meta charset="UTF-8">
<meta name="authoring-tool" content="Adobe_Animate_CC">
<title>javaTest</title>
<!-- write your code here -->
<style>
  #animation_container {
	position:absolute;
	margin:auto;
	left:0;right:0;
	top:0;bottom:0;
  }
</style>
<script src="https://code.createjs.com/1.0.0/createjs.min.js"></script>
<script src="x-javaTest.js"></script>
<script src="game.js"></script>
<script>
var canvas, stage, exportRoot, anim_container, dom_overlay_container, fnStartAnimation, game;
function init() {
	canvas = document.getElementById("canvas");
	anim_container = document.getElementById("animation_container");
	dom_overlay_container = document.getElementById("dom_overlay_container");
	var comp=AdobeAn.getComposition("A21967C6DB7943FE8681899B44492054");
	var lib=comp.getLibrary();
	handleComplete({},comp);
}
function handleComplete(evt,comp) {
	//This function is always called, irrespective of the content. You can use the variable "stage" after it is created in token create_stage.
	var lib=comp.getLibrary();
	var ss=comp.getSpriteSheet();
	exportRoot = new lib.javaTest();
	stage = new lib.Stage(canvas);	
	//Registers the "tick" event listener.
	fnStartAnimation = function() {
          game = new Game(stage, exportRoot, lib);
		stage.addChild(exportRoot);
		createjs.Ticker.framerate = lib.properties.fps;
		createjs.Ticker.addEventListener("tick", stage);
	}	    
	//Code to support hidpi screens and responsive scaling.
	AdobeAn.makeResponsive(true,'both',true,1,[canvas,anim_container,dom_overlay_container]);	
	AdobeAn.compositionLoaded(lib.properties.id);
	fnStartAnimation();
}
    function handleTick(event) {
            if (game === undefined) game = new Game(exportRoot, stage);
    }
</script>
<!-- write your code here -->
</head>
<body onload="init();" style="margin:0px;">
	<div id="animation_container" style="background-color:rgba(255, 255, 255, 1.00); width:960px; height:640px">
		<canvas id="canvas" width="960" height="640" style="position: absolute; display: block; background-color:rgba(255, 255, 255, 1.00);"></canvas>
		<div id="dom_overlay_container" style="pointer-events:none; overflow:hidden; width:960px; height:640px; position: absolute; left: 0px; top: 0px; display: block;">
		</div>
	</div>
</body>
</html>

 but when I try to put an object - a button or a movieclip on the timeline my naming doesnt work.

class Game{
    constructor(exportRoot, stage){
        this.root = exportRoot;
        this.stage = stage;
        this.init();
    }
    
    init(){
        const game = this;
game.root.rect1.gotoAndStop("red");
      }
}

I think my index is wrong somehow? Or still I am just not understanding something?

Thanks for any help

Views

561

Translate

Translate

Report

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 , Dec 28, 2022 Dec 28, 2022

There you go:
https://bit.ly/3Q3eOwC

 

I hope it helps to clarify all doubts.

Votes

Translate

Translate
Community Expert ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

don't call init before onstage instances are ready

Votes

Translate

Translate

Report

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
Participant ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

tell me more kglad?  What do I need to look at?

Votes

Translate

Translate

Report

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 ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

init should not be called from the constructor if you're going to reference onstage instances there.

Votes

Translate

Translate

Report

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
Participant ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

so you cant mix having things on the stage and added from the code in the same project?  I dont understand..

I thought the init was a special function used by JS?  

Votes

Translate

Translate

Report

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 ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

sure you can. but you have time things correctly.  use console.log to debug.

Votes

Translate

Translate

Report

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
Participant ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

ok thanks- I will keep trying

Votes

Translate

Translate

Report

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 ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

learn to debug:

 

lesson 1 - https://youtu.be/PBDQN9CQSeI

 

lesson 2 - https://youtu.be/KJEl0OenGUY

Votes

Translate

Translate

Report

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
Participant ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

Hey thanks kglad.  i watched the videos and I am already doing this.  I know where the error is, just not how to fix it.  
You are saying dont call the init() function from the constructor- so am I putting the reference to things on the stage in another function and calling it from inside the init()?  It seems like everywhere I try to put it is not working?  I watched the debug videos so what do I need to look at now?

Votes

Translate

Translate

Report

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
Participant ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

class Game{
    constructor(exportRoot, stage){
        this.root = exportRoot;
        this.stage = stage;
        this.init();
        makeitgo(){
            game.root.rect1.gotoAndPlay("on");
        }
    }
    
    init(){
        const game = this;
     this.makitgo();
  
}

}

so just to be clear its the game.js file where the issue is now?  but this is the same exact layout that works with JS from the easelJS tuts - how can I make it work for both? (clearly this one doesnt work at all!)

Votes

Translate

Translate

Report

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 ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

class Game{

constructor(exportRoot, stage){
this.root = exportRoot;
this.stage = stage;
this.init();

}

init(){
const game = this;  
//the his.makitgo();
}

makeitgo(){
game.root.rect1.gotoAndPlay("on");
}

}

///////////

 

in your fla

 

var g = new Game(exportRoot,stage)

// delay until rect1 ready

g.makeitgo();

Votes

Translate

Translate

Report

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
Participant ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

Thank you- now its throwing the error about the naming being wrongScreenshot 2022-12-29 at 10.48.28 am.png

Votes

Translate

Translate

Report

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 ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

There you go:
https://bit.ly/3Q3eOwC

 

I hope it helps to clarify all doubts.

Votes

Translate

Translate

Report

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
Participant ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied


Yes thank you this works! How and why it works is another thing - I just need to make sure I can modify it without issue but this is great- thank you for taking the time

Votes

Translate

Translate

Report

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
Participant ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

OK! I feel like I can confidently say that I can make changes to the project and change instance names and I havent broken it!  Yes!!  This was supposed to be a very simple procedure if I just followed the project along but I wanted to be able to build a project from scratch- not sure if I have acheived a full understanding here but I can look into your solution and work out how and why it works!  As always excellent! 

Votes

Translate

Translate

Report

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 ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

LATEST

Awesome!!! You're welcome!

Votes

Translate

Translate

Report

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