About Me

My photo
Derek lives in Wall Street, Lee-Over-Sands, St Osyth. A mobile and event software/product designer by trade - and is keen to improve things for all the local residents - and has lived in this idyllic location since 2009.

Thursday, 18 February 2010

Timeline frame movement oddities

If anyone has ever wanted a Flash movie to replay the code on the current frame in a timeline, basically its impossible, without mucking about with workarounds. This makes it worth mentioning in my Blog just in case someone is having trouble with this.

I've revisited this again for the first time in a year - although timelines are of course a throwback to Actionscript 1.0 techniques, its still the most efficient way of building items on a page, using timeline navigation methods to jump to a certain frame based on a button action, and of course that frame has pasted onto it all the items you want to appear, or not.

As well as the physical items on the stage, there is of course the actionscript code itself on the frame. Despite most current thinking which discourage usage of timeline based code, its still a very logical place to put it - as most applications are proceedural in nature - so its often still the most efficient way of making sure code matches visual objects at a certain part of your Flash program.

Where this falls down however, is where you want a frame to "re-execute" its code on that given frame. Why would you want to do this? Well the project I'm working on is a modification to an older app I built a couple of months ago, which is built with the method above. Now I want to force a language change using some Flag items - this means quite simply that the app needs to repopulate the page content when this happens. Of course there is also the background loading of XML files to achive this, but for the moment lets focus on the actual repopulation of your text fields, button titles etc on the current frame.

In this situation, the most obvious solution is to have the populate feature on the same frame to be activated based on the language change. Of course - this means that you may have built the whole page population methods on the timeline code.

This is where the old methods are problematic, as a command like this:
_root.gotoAndStop(this._currentframe)
won't work, you'd think it would, but no. A trace command will confirm that nothing happens. So the old workaround would be to add a blank dummy frame before each main frame in your Flash movie, then use:
_root.gotoAndStop(this._currentframe-1);
The playhead then definately moves, and the frame's actual code gets re-executed, in turn repopulating your objects on the stage.

Another approach is to put all your populate features in frame 1 into a function, then the Flag button press can call the function, irrespective of the above timeline execution issues. Of course your actionscript frame then also calls the same function as the timeline moves.

The downside of course with this is that it makes your code very hard to go through, because all the population routines are then seperated visually and structurally from where they are used, making updates harder, as you have to flick from timeline frame to frame 1's function definitions.

This is one of those odd situations where I thought it was worth pointing this out, because few Flash tutorials ever go into the actual architecture of building a Flash Application.

No comments:

Post a Comment