Piers Mana
Piers Mana

Reputation: 382

Massive efficiency issue in AS3-based timeline project

Before anything else, this is the offending bit of code:

for (var i in yearMarkersArray) {
 yearMarkersArray[i].x = ((timelines.x + 350) % 140) + (140 * i) - 5;
 yearMarkersArray[i].text = "0";
}

This is part of the main loop that triggers whenever the user drags the zoomed-out timelines (the sprites in eventsArray) left or right. The six TLFText objects in yearMarkersArray appear to scroll left or right with the user, but are really repositioned and relabeled with the correct year markers as calculated by a function I did not include above (it's working and not relevant to this problem, I simply replaced it with the "0" for clarity).

The text-setting statement is the problem code...I've commented literally everything else out of the main loop to verify it. I even changed the statement to not involve any function call (simply setting the text attribute to "0"), and it still causes the final .swf to eat an extra 1% of my CPU every 15 seconds until finally the FPS crashes through the floor. The rest of the main loop has much, MUCH more complex and I'm sure inefficient code that also runs every frame, and I have no idea why that one statement would cause so much trouble.

Since this project reads a data file with a list of timeline events whose span of years I cannot predict, I do need the displayed year markers to be done dynamically in some way. The code ultimately works (I only noticed the ridiculous slowdown when I accidentally left the movie open and idle for a few minutes), but I'm quite new to Flash and entirely up for alternate solutions if they're available. Thanks in advance for the advice!

Upvotes: 1

Views: 161

Answers (2)

Piers Mana
Piers Mana

Reputation: 382

TLFText is very slow to dynamically alter, and should really only be used for text that needs that extra formatting. Dynamic Classic text is the way to go for small, changeable fields.

Upvotes: 1

The_asMan
The_asMan

Reputation: 6402

This is part of the main loop that triggers whenever the user drags the zoomed-out timelines

Are you calling this loop from on drag start or on drag move?

If on drag move that is your problem

Upvotes: 0

Related Questions