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

Clearing Array HTML5 - I think?

New Here ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

Hello

 

Fairly new to javaScript/Animate so the code might be a bit sketchy but.... I think I need to clear the array somehow on the attached project, each time I move between sections.

 

Download .fla here

 

It is basically a load of circles that use vectors to move around the screen in a 'random' fashion. These objects are connected by lines which are drawn in a shape object.

 

It all works fine except when I go to another location and then return to the main screen, the number of lines doubles and they appear to be tracking ghost objects. Every time you leave and return another set of lines appears...

 

I am guessing this is because I keep creating(?)/adding to(?) the existing array of objects but can't find a way to clear or block this happening.

 

Creating the array and graphic for the lines in the 'global/script' section seemed to stop additional lines being created but then the speed of movement doubled each time you return to the home screen.

 

Another issue is that the lines continue to be drawn in the 'test' frame even though I am not calling any code here to do so..

 

Any pointers would be greatly appreciated. Cheers 🙂

 

Click on a circle to go to the 'test' frame and then click the 'home' button to return home and see the madness!

Views

236

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

Engaged , Feb 24, 2022 Feb 24, 2022

Hi,
I haven't dig too much into the logic of the code, but I noticed that
_this.addChild (linesObject);
is executed multiple times.
I moved these two lines
_this.addChild( linesObject );
_this.setChildIndex( linesObject, 0 );
immediately after the initialization of linesObject and I think, now it works as expected.
See the attachment.

 

 

 

Votes

Translate

Translate
Engaged ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

Hi,
I haven't dig too much into the logic of the code, but I noticed that
_this.addChild (linesObject);
is executed multiple times.
I moved these two lines
_this.addChild( linesObject );
_this.setChildIndex( linesObject, 0 );
immediately after the initialization of linesObject and I think, now it works as expected.
See the attachment.

 

 

 

- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation

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
New Here ,
Feb 26, 2022 Feb 26, 2022

Copy link to clipboard

Copied

LATEST

Thanks Vladin

 

Working perfectly. Didn't realise I should be clearing the linesObject as well.

 

Much appreciated 🙏

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