Highlighted

How Can I Learn Javascript in Adobe Animate?

New Here ,
May 14, 2020

Copy link to clipboard

Copied

[INTRO]

 

I've been writing codes for a year now, and many people have told me that I'm the worst programmer there is. I know the basics, but somehow I missed some of the fundamentals and the concepts, and now I'm stucked at my game development. I'm using Javascript in Adobe Animate to create a very very tiny game that only involves clicking with mouse.

 

I followed a tutorial posted in this is site (this one) . I didn't copy the whole thing tho, I just trying to learn the basics and methods he's using. Now, there's a part in that tutorial that explains a bit about prototype. I have no idea what that is, and I just used it ignorantly as a way to bridge one function to another.

 

[CODES]

I have three scripts thatis distributed in three layers:

function Main(){
	this.Litter = new Litter();
	this.Money = new Money();
	
	litterP = 0;
	moneyP = 0;
	
	createJS.Ticker._addEventListener("tick", this.update.bind(this));
}


Main.prototype.update = function(evt){

	this.litterP=this.Litter.update();
	this.moneyP=this.Money.update();
	console.log("Main::update()");
}

 

----------------------------

 

function Money(){
	this._moneyP = 0;
}

Money.prototype.update = function()
{
	return this._moneyP;
}

Money.prototype.getMoneyP = function(){
	this._moneyP=this._moneyP+1;
	exportRoot.money_1.visible=false;
	exportRoot.moneyP_text.text=this._moneyP;
}

exportRoot.money_1.addEventListener("click", Money.prototype.getMoneyP.bind(this));

 

--------------------------------

 

function Litter(){
	this._litterP=0;
}

Litter.prototype.update=function()
{
	return this._litterP;

}

Litter.prototype.getLitterP = function(){
		this._litterP=this._litterP_litterP+1;
		exportRoot.lit_1.visible = false;
		
		exportRoot.litterP_text.text=this._litterP;
	
}


exportRoot.lit_1.addEventListener("click", Litter.prototype.getLitterP.bind(this));

 

[PROBLEMS]

 

Everytime the instance called "lit_1", the value of litter_1 should be added by 1, and then its value should be printed in a textbox called "litterP_text". When I tried to click, instead of displaying "1", it displays "NaN". It seems like the value of litter_1 is undefined. The same thing happens to the money_1.

 

How can I solve this?

 

[QUESTIONS]

 

  1. What is this prototype?
  2. How can I access the variables declared on the parent function and access it in the prototype function?
  3. As a beginner, where can I learn Javascript in Adobe Animate? (I'm not talking about the documentation that is extremely hard to comprehend. Besides, my first language is not English, so I can't understand those technical languages most of them are using)

 

[Note]

 

I've frustrated many people with my code, so before you complain, I would to apologize. Thank you for reading.

TOPICS
Code, How to

Views

247

Likes

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

How Can I Learn Javascript in Adobe Animate?

New Here ,
May 14, 2020

Copy link to clipboard

Copied

[INTRO]

 

I've been writing codes for a year now, and many people have told me that I'm the worst programmer there is. I know the basics, but somehow I missed some of the fundamentals and the concepts, and now I'm stucked at my game development. I'm using Javascript in Adobe Animate to create a very very tiny game that only involves clicking with mouse.

 

I followed a tutorial posted in this is site (this one) . I didn't copy the whole thing tho, I just trying to learn the basics and methods he's using. Now, there's a part in that tutorial that explains a bit about prototype. I have no idea what that is, and I just used it ignorantly as a way to bridge one function to another.

 

[CODES]

I have three scripts thatis distributed in three layers:

function Main(){
	this.Litter = new Litter();
	this.Money = new Money();
	
	litterP = 0;
	moneyP = 0;
	
	createJS.Ticker._addEventListener("tick", this.update.bind(this));
}


Main.prototype.update = function(evt){

	this.litterP=this.Litter.update();
	this.moneyP=this.Money.update();
	console.log("Main::update()");
}

 

----------------------------

 

function Money(){
	this._moneyP = 0;
}

Money.prototype.update = function()
{
	return this._moneyP;
}

Money.prototype.getMoneyP = function(){
	this._moneyP=this._moneyP+1;
	exportRoot.money_1.visible=false;
	exportRoot.moneyP_text.text=this._moneyP;
}

exportRoot.money_1.addEventListener("click", Money.prototype.getMoneyP.bind(this));

 

--------------------------------

 

function Litter(){
	this._litterP=0;
}

Litter.prototype.update=function()
{
	return this._litterP;

}

Litter.prototype.getLitterP = function(){
		this._litterP=this._litterP_litterP+1;
		exportRoot.lit_1.visible = false;
		
		exportRoot.litterP_text.text=this._litterP;
	
}


exportRoot.lit_1.addEventListener("click", Litter.prototype.getLitterP.bind(this));

 

[PROBLEMS]

 

Everytime the instance called "lit_1", the value of litter_1 should be added by 1, and then its value should be printed in a textbox called "litterP_text". When I tried to click, instead of displaying "1", it displays "NaN". It seems like the value of litter_1 is undefined. The same thing happens to the money_1.

 

How can I solve this?

 

[QUESTIONS]

 

  1. What is this prototype?
  2. How can I access the variables declared on the parent function and access it in the prototype function?
  3. As a beginner, where can I learn Javascript in Adobe Animate? (I'm not talking about the documentation that is extremely hard to comprehend. Besides, my first language is not English, so I can't understand those technical languages most of them are using)

 

[Note]

 

I've frustrated many people with my code, so before you complain, I would to apologize. Thank you for reading.

TOPICS
Code, How to

Views

248

Likes

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
May 14, 2020 0

Have something to add?

Join the conversation