Skip to main content
Participant
July 9, 2020
Answered

Adapting AS2 function

  • July 9, 2020
  • 1 reply
  • 390 views

Hi, I'm trying to transform an old educational simulation to HTML5 Canvas with Animate CC and I still can't find my way. If you can help me, I am very grateful. This is the function:

 

function alfafire() {
i++;
duplicateMovieClip ("alfas", "alfas" + i, 1000 + i);
clearInterval(afint);
afint = setInterval(alfafire, 200 + (Math.random() * 1000));
}

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

 

Please tell us if this approach works for you:

 

 

var afint;

function alfafire(container)
{	
	var alfas = new lib.alfas(); // alfas is the linkage name in the Library for the symbol you want to add at runtime
	alfas.x = canvas.width * Math.random();
	alfas.y = canvas.height * Math.random();
	container.addChild(alfas);
	clearInterval(afint);
	afint = setInterval(alfafire, 200 + Math.random() * 1000, container);
}

alfafire(this);

 

 

 

Regards,

JC

1 reply

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
July 9, 2020

Hi.

 

Please tell us if this approach works for you:

 

 

var afint;

function alfafire(container)
{	
	var alfas = new lib.alfas(); // alfas is the linkage name in the Library for the symbol you want to add at runtime
	alfas.x = canvas.width * Math.random();
	alfas.y = canvas.height * Math.random();
	container.addChild(alfas);
	clearInterval(afint);
	afint = setInterval(alfafire, 200 + Math.random() * 1000, container);
}

alfafire(this);

 

 

 

Regards,

JC

Participant
July 9, 2020

Thank you very much Joao,
it works perfectly!!

JoãoCésar17023019
Community Expert
Community Expert
July 9, 2020

Awesome! You're welcome!