You must be logged in to post Login Register
Search 

controlling the timeline with if statement

User Post

4:39 pm
June 6, 2009


ujaraju

New Member

posts 2

1

I am working on my portfolio where the intro starts and stops at frame 525

at frame 525 i have bunch of codes to load the external swf files when respective button is clicked

it works fine until here

but i want to put conditions on each buttons such that

if the playhead is at frame 525,

when a button is clicked,

goto and play frame called”start”

else just load the swf


here is the site http://www.rajumaharjan.com

following is the code at frame 525


stop();
//for reflection
import com.pixelfumes.reflect.*;
var r1:Reflect = new Reflect({mc:btn_bio, alpha:25, ratio:200, distance:5, updateTime:0, reflectionDropoff:1.2});
var r2:Reflect = new Reflect({mc:btn_resume, alpha:25, ratio:200, distance:5, updateTime:0, reflectionDropoff:1.2});
var r3:Reflect = new Reflect({mc:btn_projects, alpha:25, ratio:200, distance:5, updateTime:0, reflectionDropoff:1.2});
var r4:Reflect = new Reflect({mc:btn_contact, alpha:25, ratio:200, distance:5, updateTime:0, reflectionDropoff:1.2});
var r5:Reflect = new Reflect({mc:cartoon, alpha:25, ratio:160, distance:0, updateTime:0, reflectionDropoff:1.2});

//Assign CLICK listeners for each menu button
btn_bio.addEventListener (MouseEvent.CLICK, buttonClicked);
btn_resume.addEventListener (MouseEvent.CLICK, buttonClicked);
btn_projects.addEventListener (MouseEvent.CLICK, buttonClicked);
btn_contact.addEventListener (MouseEvent.CLICK, buttonClicked);
home.addEventListener (MouseEvent.CLICK, buttonClicked);
mail.addEventListener (MouseEvent.CLICK, buttonClicked);
 
//Make the buttons look like buttons (hand cursor appears on hover)
btn_bio.buttonMode = true;
btn_resume.buttonMode = true;
btn_projects.buttonMode = true;
btn_contact.buttonMode = true;
 
//This loader is used to load the external swf files
var loader:Loader;

import fl.transitions.*;
import fl.transitions.easing.*;

 
//URLRequest stores the path to the file to be loaded
var urlRequest:URLRequest;
 
//This array holds all the tweens, so they
//don't get garbage collected
var tweens:Array = new Array();

 
//Stores the current page we are displaying
var currentPage:MovieClip = null;
 
//Stores the next page that we are going to display
var nextPage:MovieClip = null;
 
//This function is called when a menu button is clicked
function buttonClicked (e:Event):void {
 
 //Create a new loader instance
 loader = new Loader();
 
 //If we clicked the first button, we load the page1
 
 if (e.target == btn_bio) {  
  urlRequest = new URLRequest(“page_bio.swf”);
  loader.load (urlRequest);
 }
 
 //If we clicked the second button, we load the page2
 else if (e.target == btn_resume) {
 
  urlRequest = new URLRequest(“page_resume.swf”);
  loader.load (urlRequest);
 }
 
 //If we clicked the second button, we load the page2
 else if (e.target == btn_projects) {
 
  urlRequest = new URLRequest(“page_project.swf”);
  loader.load (urlRequest);
 }
 
 //when home icon is pressed OPENS BIO PAGE *****FOR TEST
 else if (e.target == home) {
 
  urlRequest = new URLRequest(“page_bio.swf”);
  loader.load (urlRequest);
 }
 //when mail icon is pressed
 else if (e.target == mail) {
 
  urlRequest = new URLRequest(“page_contact.swf”);
  loader.load (urlRequest);
 }
 
 //We load page3 since we know that page01Button or page02Button
 //is not clicked
 else {
 
  urlRequest = new URLRequest(“page_contact.swf”);
  loader.load (urlRequest);
 }
 
 //We want to know when the next page is finished loading
 loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fileLoaded);
 
}
 
//This function is called, when we have finished loading a content page
function fileLoaded(e:Event):void {
 
 //The loader contains the page we are going to display.
 nextPage = e.target.content;
 
 //Let's animate the current page away from the stage.
 //First, we need to make sure there is a current page on the stage.
 if(currentPage != null) {
 
  //Tween the current page from left to the right
  var tweenX:Tween = new Tween(currentPage, “x”, Regular.easeOut,
      currentPage.x, 500, 1, true);
 
  //Decrease the alpha to zero
  var tweenAlpha:Tween = new Tween(currentPage, “alpha”, Regular.easeOut,
      1, 0, 1, true);
 
  //Push the tweens into an array
  tweens.push(tweenX);
  tweens.push(tweenAlpha);
 
  //currentPageGone will be called when the tween is finished
  tweenX.addEventListener(TweenEvent.MOTION_FINISH, currentPageGone);
 }
 
 //There is no current page, so we can animate the next
 //page to the stage. The animation is done in
 //the showNextPage function.
 else {
  showNextPage();
 }
}
 
//This function animates and displayes the next page
function showNextPage():void {
 
  //Tween the next page from left to the center
  var tweenX:Tween = new Tween(nextPage, “x”, Regular.easeOut,
      -200, 0, 1, true);
 
  //Tween the alpha to from 0 to 1
  var tweenAlpha:Tween = new Tween(nextPage, “alpha”, Regular.easeOut,
      0, 1, 1, true);
 
  //Push the tweens into an array
  tweens.push(tweenX);
  tweens.push(tweenAlpha);
 
  //Add the next page to the stage
  addChild(nextPage);
 
  //Next page is now our current page
  currentPage = nextPage;
}
 
//This function is called when the current page has been animated away
function currentPageGone(e:Event):void {
 
 //Remove the current page completely
 removeChild(currentPage);
 
 //show the next page
 showNextPage();
}

//this is for button activation and deactivation
//…………………………………………………………….
var buttonsArray:Array = [btn_bio,btn_resume,btn_projects,btn_contact];

function setButtons():void {
 for (var i:int=0; i   buttonsArray[i].id = i;
  buttonsArray[i].buttonMode = true;
  buttonsArray[i].mouseChildren = false;
  buttonsArray[i].mouseEnabled = true;
  buttonsArray[i].addEventListener(MouseEvent.ROLL_OVER,playOver);
  buttonsArray[i].addEventListener(MouseEvent.ROLL_OUT,playOut);
  buttonsArray[i].addEventListener(MouseEvent.CLICK,doClick);
 }
}

function playOver(event:MouseEvent):void {
 event.currentTarget.gotoAndPlay(“over”);
}

function playOut(event:MouseEvent):void {
 event.currentTarget.gotoAndPlay(“out”);
}

function doClick(event:MouseEvent):void{
 var currentBtn:int = event.currentTarget.id;
 setSelectedBtn(currentBtn);
}
function setSelectedBtn(id:int):void{
 for (var i:int=0; i< buttonsArray.length; i++) {
  if (id == i) {
   buttonsArray[i].gotoAndStop(“down”);
   buttonsArray[i].buttonMode = false;
   buttonsArray[i].mouseEnabled = false;
   buttonsArray[i].removeEventListener(MouseEvent.ROLL_OVER,playOver);
   buttonsArray[i].removeEventListener(MouseEvent.ROLL_OUT,playOut);
   buttonsArray[i].removeEventListener(MouseEvent.CLICK,doClick);
  } else {
   if(buttonsArray[i].currentLabel ==”down”){
    buttonsArray[i].gotoAndPlay(“out”);
   }
   buttonsArray[i].buttonMode = true;
   buttonsArray[i].mouseEnabled = true;
   buttonsArray[i].addEventListener(MouseEvent.ROLL_OVER,playOver);
   buttonsArray[i].addEventListener(MouseEvent.ROLL_OUT,playOut);
   buttonsArray[i].addEventListener(MouseEvent.CLICK,doClick);
  }
 }
}
setButtons();

//for sound

//imports the necessary as events
import flash.events.Event
import flash.events.MouseEvent;

var isPlaying:Boolean = new Boolean();
var pausePosition:Number = new Number();

//Create an instance of the Sound class
var soundClip:Sound = new Sound();
//Create a new SoundChannel Object
var sndChannel:SoundChannel = new SoundChannel();

//Load sound using URLRequest
soundClip.load(new URLRequest(“song.mp3″));
//Create an event listener that wll update once sound has finished loading
soundClip.addEventListener(Event.COMPLETE, onComplete, false, 0, true);

controller.addEventListener(MouseEvent.MOUSE_DOWN, btnPressController, false, 0, true);
//stop_btn.addEventListener(MouseEvent.MOUSE_DOWN, btnPressStop, false, 0, true);

function onComplete(evt:Event):void {
 //Play loaded sound
 sndChannel = soundClip.play(0,9999999999999999);
 isPlaying = true;
}

function btnPressController(evt:MouseEvent):void
{
 switch(isPlaying)
 {
  case true:
   controller.gotoAndStop(2);
   pausePosition = sndChannel.position;
   sndChannel.stop();
   isPlaying = false;
  break;
  case false:
   controller.gotoAndStop(1);
   sndChannel = soundClip.play(pausePosition);
   isPlaying = true;
  break;
 }
}

function btnPressStop(evt:MouseEvent):void
{
 pausePosition = 0;
 sndChannel.stop();
 controller.gotoAndStop(2);
 isPlaying = false;
}

Topic RSS 
Search