A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Using if statement to check what frame a movie clip is on

  1. #1
    Member
    Join Date
    Feb 2005
    Posts
    48

    Using if statement to check what frame a movie clip is on

    Hi there,

    I need some help. What I have is a movieclip (instance name "nystate") with 3 keyframes in it, each keyframe has a movieclip with an instance name ("Start", "democrat" , "republican").

    What I need to do is run an if statement that can look at the nystate movieclip and check what frame it is on. If on frame "Start" do this, else if on frame "democrat" do this else on frame" republican" do this.

    How do I get the if statement to read which frame it's on? Also is it possible to do this with just frame labels, so I don't have to create mcs for the 3 frames.

    To give you an overview of the project, it's a US election map that allows the user to choose democrat or republican for each of the 50 states, when they choose the party it adds a predefined figure to the total for that party.

    What I need the if statement to do is know what party each state is on and change the total figures accordingly.

    eg if the state is democrat and it gets changed to republican the totals need to change as follows, add number to Republican total and delete from democrat total. I've got the functions defined for updating the totals it's just the checking what party (if any) has been assigned to each state.

    Hope that makes sense!

    Here's where I'm at so far...

    var arr:Array = new Array();
    arr[0] = {NameRep:"nybtnRep", NameDem:"nybtnDem", Score:40, State:"nystate"};
    arr[1] = {NameRep:"massbtnRep", NameDem:"massbtnDem", Score:22, State:"massstate"};
    len = arr.length;
    for (var n = 0; n != len; n++) {
    sco = arr[n].Score;
    refDem = arr[n].NameDem;
    refRep = arr[n].NameRep;
    stat = arr[n].State;
    buttonsRep(refRep, sco, stat, statRep);
    buttonsDem(refDem, sco, stat, statDem);
    }

    function buttonsDem(refDem, sco, stat) {
    _root[refDem].onPress = function() {
    if(_root[stat].Start);{
    _root[stat].gotoAndStop("democrat");
    addDemScore(sco);
    txtDem.text = scoreDem+"";
    this.enabled=false;

    }

    if(_root[stat].Republican);
    {_root[stat].gotoAndStop("democrat");
    addDemScore(sco);
    txtDem.text = scoreDem+"";
    deleteRepScore(sco);
    txtRep.text = scoreRep+"";
    }
    }}

  2. #2
    Member
    Join Date
    May 2007
    Posts
    39
    here's a simple if statement to check the frame of a MC:
    Code:
    if(nystate._currentframe == 1) {
    	trace('nystate is at "Start"');
    } else if(nystate._currentframe == 2) {
    	trace('nystate is at "democrat"');
    } else {
    	trace('nystate is at "republican"');
    }

  3. #3
    Member
    Join Date
    Feb 2005
    Posts
    48
    thanks Dongerman,

    So to use it in conjunction with the array it will be something like...

    if(_root[stat]._currentframe == 1) {
    trace('nystate is at "Start"');
    } else if(_root[stat]._currentframe == 2) {
    trace('nystate is at "democrat"');
    } else {
    trace('nystate is at "republican"');
    }

  4. #4
    Member
    Join Date
    May 2007
    Posts
    39
    you got it!

    Code:
    if(_root[stat]._currentframe == 1) {
    	trace(_root[stat]._name+' is at "Start"');
    } else if(_root[stat]._currentframe == 2) {
    	trace(_root[stat]._name+' is at "democrat"');
    } else {
    	trace(_root[stat]._name+' is at "republican"');
    }

  5. #5
    Member
    Join Date
    Apr 2007
    Posts
    73
    My question is similar so I'll post it here- I have a frame action that loads a movie into a target:

    Code:
    tiny_clear_port.onPress = function(){
    	containerArt.loadMovie("portfolio1.swf");
    }
    However, if the playhead is in frames 60-64 I don't want it to load. How do I create an if statement that will load the above clip UNLESS the playhead is currently in frames 60-64, in which case I want nothing to happen? It's probably fairly easy to figure out based on what's been given in this thread, but I'm new with "if" statements and could use the extra help. Thanks!

  6. #6
    Member
    Join Date
    May 2007
    Posts
    39
    if the "tiny_clear_port" button is on the timeline you want to analyze:

    Code:
    tiny_clear_port.onPress = function(){	
    	if(this._parent._currentframe < 60 || this._parent._currentframe > 64) {
    		containerArt.loadMovie("portfolio1.swf");
    	}
    }

  7. #7
    Member
    Join Date
    Apr 2007
    Posts
    73
    awesome- thanks!

  8. #8
    Member
    Join Date
    Feb 2005
    Posts
    48
    Hi there,

    I'm reclaiming back my thread!! I've managed to get the if statement to do exactly what I want it to do, but when it's used in conjunction with the array it starts behaving strangely.

    This is basically what I have done using the if statements to check what frame the state movie clips are on...

    //Buttons and states array and functions
    var arr:Array = new Array();
    arr[0] = {NameRep:"nybtnRep", NameDem:"nybtnDem", Score:40, State:"nystate"};
    arr[1] = {NameRep:"massbtnRep", NameDem:"massbtnDem", Score:22, State:"massstate"};
    arr[2] = {NameRep:"cabtnRep", NameDem:"cabtnDem", Score:60, State:"castate"};
    len = arr.length;
    for (var n = 0; n != len; n++) {
    sco = arr[n].Score;
    refDem = arr[n].NameDem;
    refRep = arr[n].NameRep;
    stat = arr[n].State;
    buttonsRep(refRep, sco, stat);
    buttonsDem(refDem, sco, stat);
    }
    function buttonsRep(refRep, sco, stat) {
    _root[refRep].onPress = function()
    {if(_root[stat]._currentframe == 1) {
    _root[stat].gotoAndStop(3);
    addRepScore(sco);
    txtRep.text = scoreRep+"";
    this.enabled=false;
    _root[refDem].enabled=true;
    }
    else if(_root[stat]._currentframe == 2) {
    _root[stat].gotoAndStop(3);
    addRepScore(sco);
    txtRep.text = scoreRep+"";
    deleteDemScore(sco);
    txtDem.text = scoreDem+"";
    this.enabled=false;
    _root[refDem].enabled=true;
    }
    }
    }
    function buttonsDem(refDem, sco, stat) {
    _root[refDem].onPress = function()
    {if(_root[stat]._currentframe == 1) {
    _root[stat].gotoAndStop(2);
    addDemScore(sco);
    txtDem.text = scoreDem+"";
    this.enabled=false;
    _root[refRep].enabled=true;
    }
    else if(_root[stat]._currentframe == 3) {
    _root[stat].gotoAndStop(2);
    addDemScore(sco);
    txtDem.text = scoreDem+"";
    deleteRepScore(sco);
    txtRep.text = scoreRep+"";
    this.enabled=false;
    _root[refRep].enabled=true;
    }
    }
    }

    What happens is they all work fine until all the buttons have been clicked on then the all the buttons are disabled except for the last two to be put on the stage, in this case cabtnRep and cabtnDem.

    I was wondering if it's because they're all on the same layer or whether I need to use the getNextHighestDepth command in some way.

    I can email the .FLA if anyone fancies taking a look at it for me.

    Best
    Steve

  9. #9
    Member
    Join Date
    May 2007
    Posts
    39
    can you attach the FLA to a post please and i'll take a look at it.

  10. #10
    Member
    Join Date
    Feb 2005
    Posts
    48
    would love to but it's 800k, only allowed 400.

    if you email me at stevendbernard@yahoo.com I'll reply to you from there

    Best
    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center