Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

RunPseudoScenes.as

Name: RunPseudoScenes - [MX] emulate scene progression through mcs in sequential frames in the main T.L.
Author: senocular: www.senocular.com
Date: 1899-12-31T00:34:22.100
Documentation:
RunPseudoScenes: Emulates 'scenes' from movieclips
placed on the timeline in sequential frames, i.e. Scene1
would be a movieclip in frame 1 of _root; Scene2 would
be a movieclip in frame 2 of _root etc. allowing you to
have 'scenes' as movieclips placed one by one in the main
timeline.

RunPseudoScenes();
- sets up the pseudo-scene emulation. This can be put in any timeline (technically) though
most suitable for _root - and can only be used once per level. What RunPseudoScenes does is 
checks every frame to see if the current scene movieclip's current frame is on the last frame
or not.  If so, it will then (after that frame is played), move on to the next frame in the
current timeline allowing the next movieclip in the next frame play until its end where then
the process will repeat. RunPseudoScenes finds the movieclips which are the 'scenes' in each
frame on its own by grabbing what should be the only movieclip in that timeline. You dont need
to give them any special name; however, because this is the case, you have to be sure to have
only the scene movieclip in that frame.  If you need another movieclip within that frame, use
a _ns in that movieclips instance name as, then, RunPseudoScenes will ignore it when attempting
to get the scene clip (_ns for Not a Scene).

Arguments:
- none

Returns:
- true if the implementation was successful, false if not. An unsuccessful result occurs
when the timeline's onEnterFrame has been defined.  RunPseudoScenes assumes you wont be
using that timeline's (usually _root) onEnterFrame so takes it for itself.  If its already
taken, RunPseudoScenes doesnt do its thing, false is returned and the onEnterFrame is kept.

RunPseudoScenes can only be used once for each level.


Other Functions are added to extend the usability of RunPseudoScenes:

stopScene();
restartScene();
gotoAndStopScene(SceneFrame, MovieClipFrame);
gotoAndPlayScene(SceneFrame, MovieClipFrame);


stopScene();
- stops the current timeline and prevents scene progression in the RunPseudoScenes timeline.
You really only need this on the last frame of a 'scene' since otherwise, RunPseudoScenes
wouldnt try to go to the next scene unless you're on the last frame of the current scene.

restartScene();
- restarts a stopped scene.

Example:
RunPseudoScenes();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
MovieClip.prototype.RunPseudoScenes = function(){
	if (this.onEnterFrame) return false;
	this.lastFrame = false;
	_root.scene = this;
	this.getScene = function(){
		for (i in this) if (typeof this[i] == "movieclip" && this[i]._parent == this && i.indexOf("_ns")<0) return this.currScene = this[i];
		return this.currScene = false;
	};
	this.getScene();
	this.stop();
	this.onEnterFrameBAK = this.onEnterFrame = function(){
		if (this.lastFrame){
			this.lastframe = false;
			if (this._currentframe == this._totalframes) this.gotoAndStop(1);
			else this.nextFrame();
			this.getScene();
		};
		if (this.currScene){ if (this.currScene._currentframe == this.currScene._totalframes) this.lastframe = true;
		}else if (!this.currScene){
			trace("No scene movieclip found.\nRunning of pseudo-scenes halted.");
			delete this.onEnterFrame;
		};
	};
	return true;
};
MovieClip.prototype.stopScene = function(){
	this.stop();
	delete _root.scene.onEnterFrame;
	_root.scene.lastFrame = false;
};
MovieClip.prototype.restartScene = function(){
	_root.scene.onEnterFrame = _root.scene.onEnterFrameBAK;
};
MovieClip.prototype.gotoAndPlayScene = function(label, frame){
	_root.scene.gotoAndStop(label);
	_root.scene.getScene();
	if (frame == undefined) frame = 1;
	_root.scene.currScene.gotoAndPlay(frame);
	if (!_root.scene.onEnterFrame) _root.scene.onEnterFrame = _root.scene.onEnterFrameBAK;
};
MovieClip.prototype.gotoAndStopScene = function(label, frame){
	_root.scene.gotoAndStop(label);
	_root.scene.getScene();
	if (frame == undefined) frame = 1;
	_root.scene.currScene.gotoAndStop(frame);
	if (!_root.scene.onEnterFrame) _root.scene.onEnterFrame = _root.scene.onEnterFrameBAK;
};
ASSetPropFlags(MovieClip.prototype,null,1);