Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411679 Posts in 69399 Topics- by 58453 Members - Latest Member: Arktitus

May 17, 2024, 11:45:49 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Flash timeline object persistance
Pages: [1]
Print
Author Topic: Flash timeline object persistance  (Read 760 times)
dustin
Level 6
*


View Profile
« on: April 01, 2010, 06:50:51 PM »

So somethings going on that I don't understand in flash...

Here's how it goes...

1. I layout my levels in the flash ide and give the objects names for example ball1, ball2, ball3, player.

2.  Each level has it's own frame.  When I load a frame I loop through all the children and if they are derived from my actor class then add them to an array so that their update code get's run.

3.  I'm using flash cs3

The problem

I start the game and in level 1 I move the ball named ball1 to x,y 0,0
I then go to the next level (next frame).  The ball that is on this frame named ball1 doesn't appear where it should it appears at 0,0.  

Basically the objects seem to be persistent from frame to frame if I name them the same thing?  But then...

I start the game the same way as last time except now on frame 2 I have named my ball from ball1 to ball2.  Now when I go to the next level the ball appears where it should but now when I go to level 3 which does contain a ball1 it appears where it should and not where the ball1 from frame 1 was put.

So it seems they are persistent but only if the frames are right next to each other?  This just seems pretty weird to me and I'm wondering if anyone can shed any light on this.
Logged
benologist
Level 0
*


View Profile
« Reply #1 on: April 01, 2010, 09:01:35 PM »

The objects don't necessarily persist across frames, especially just with the instance name being the same.  Even when it's literally the same object on its own layer that spans all frames it is not always going to persist since some operations (eg setting the level/layer index)  will make it local to that specific frame.

What I do is design the levels in movieclips and then when you start a level you examine that movieclip and re-produce it rather than using it directly, and persist whatever necessary playing data yourself seperately.

So you have something like
- create an instance of level 1 clip with stuff here, here and here (in your case you go to that frame)
- iterate through the children via getChildAt in conjunctino with clip.numChildren
- create an instance of each object, or apply relevant data to persistant objects (player.x = level.startingpont.x)

That way the designed levels are just a guide and you have no specific dependency on them.

Hope that helps.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic