[AS3] I want a number of scenes to change once the user has looked at each once.
Hey guys, I was wondering if you could help me.
I’m making an interactive kind of game, and I want a number of scenes to change once the user has looked at each once.
For example, they go into three different scenes. When they finish looking at them all, Flash records this, and then when they look back at each scene again, they’ve all changed.
Here's one way to do it. Create an array to record whether a scene is new or viewed. Then, when a scene has been viewed, test if all have been viewed.
Here's some code:
ActionScript Code:
// set an array to keep track of whether scenes are new or viewed// start with all scenes being newvar scene_viewed:Array=newArray("new","new","new");
// when a scene is visited, change its value in the array// // to test the code comment out some of the following lines
scene_viewed[0]="viewed";
scene_viewed[1]="viewed";
scene_viewed[2]="viewed";
//whenever a scene is viewed, check to see if all scenes have been viewed
check_if_all_viewed();
function check_if_all_viewed():void{var viewed_scenes:int=0;
var i:int;
for(i=0; i<scene_viewed.length; i++){trace("checking scene "+i+": "+scene_viewed[i]);
if(scene_viewed[i]=="viewed"){
viewed_scenes++;
trace("number of viewed scenes = "+viewed_scenes);
}}if(viewed_scenes==scene_viewed.length){trace("change all scenes");
// put change scenes actions here// then reset the array to newfor(i=0;i<scene_viewed.length;i++){
scene_viewed[i]="new";
}trace(scene_viewed);
}else{trace("sorry only "+viewed_scenes+" out of "+scene_viewed.length+" have been viewed");
}}