dcsimg
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: [RESOLVED] For Loop - Changing section

  1. #1
    Bmcc*81 bmcc81's Avatar
    Join Date
    Jul 2007
    Location
    Montreal
    Posts
    299

    resolved [RESOLVED] For Loop - Changing section

    Hi,

    I have this timer code that I want to use to change my sections every 2 secs.

    Code:
    var DoRandom = function() {
    	var target_x = home_x - content_mc.section_1._x;
    	content_mc.slideTo( target_x, "0", 2 ); 
    }
    
    
    var intervalID = setInterval(DoRandom, 2000);
    So I want section_1 go to section_2 and so on every time it goes through the loop.

    Is there away to put a for loop in there?

    So it adds 1 to section_ everytime?

    This is what I thought.

    Code:
    var DoRandom = function () {
    for (i=1; i<=section_; i++) {
    var target_x = home_x-content_mc.section_1._x;
    content_mc.slideTo(target_x,"0",2);
    }
    };
    
    
    var intervalID = setInterval(DoRandom, 1000);
    I just want to add 1 to section_ everytime it goes through the loop.
    Bmcc81
    Flash Designer / Web Developer
    -----------------------------------
    http://www.webinkgraphics.com

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    try-
    PHP Code:
    var i:Number 1;

    function 
    DoRandom() {
    var 
    target_x home_x content_mc["section_"+i]._x;
    content_mc.slideTotarget_x"0"); 
    i++;
    };

    var 
    intervalID setInterval(DoRandom2000); 

  3. #3
    Bmcc*81 bmcc81's Avatar
    Join Date
    Jul 2007
    Location
    Montreal
    Posts
    299

    Thanks

    and once it's finished I want it to got hte end .

    I just wrote
    Code:
    if (target_x == home_x-content_mc.section_4._x) {
    	content_mc.slideTo(target_x,"0",2);
    	var alphaT:Tween = new Tween(b_0, "_alpha", Regular.easeOut, 50, 70, 1, true);
    }
    Is taht the right idea?
    Bmcc81
    Flash Designer / Web Developer
    -----------------------------------
    http://www.webinkgraphics.com

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    the syntax is OK
    whether it works in your project is impossible to say from here

  5. #5
    Bmcc*81 bmcc81's Avatar
    Join Date
    Jul 2007
    Location
    Montreal
    Posts
    299
    Ya It doesn't work in my project.

    How would I change he alpha to my buttons when I change sections?
    Bmcc81
    Flash Designer / Web Developer
    -----------------------------------
    http://www.webinkgraphics.com

  6. #6
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    possibly try looping to check the if(condition) ??
    PHP Code:
    this.onEnterFrame = function(){
    if (
    target_x == home_x-content_mc.section_4._x) {
    this.onEnterFrame null;
        
    content_mc.slideTo(target_x,"0",2);
        var 
    alphaT:Tween = new Tween(b_0"_alpha"Regular.easeOut50701true);
    }
    }; 
    pretty much impossible for me to go any further with this one, sorry

  7. #7
    Bmcc*81 bmcc81's Avatar
    Join Date
    Jul 2007
    Location
    Montreal
    Posts
    299

    So check this out - SlideShow Menu Action Accomplished

    Hey,

    I figured it out.
    I used clearInterval.

    It worked great. I used an if statement with the clearInterval.

    And to send it back TO THE START...
    Also an if statment but I just added to the if (i==6)

    Code:
    var target_x = home_x-content_mc.section_0._x;
    	content_mc.slideTo(target_x,"0",2);

    Code:
    var i:Number = 1; 
    
    function DoRandom() { 
    var target_x = home_x - content_mc["section_"+i]._x; 
    var alphaT:Tween = new Tween(["section_"+i], "_alpha", Regular.easeOut, 50, 70, ["b_"]+i, true);
    content_mc.slideTo( target_x, "0", 2 ); 
    i++; 
    if(i==6) clearInterval(intervalID);
    if(i==6) var target_x = home_x-content_mc.section_0._x;
    	content_mc.slideTo(target_x,"0",2);
    }   
    
    var intervalID = setInterval(DoRandom, 2000);
    Pretty cool,

    Thanks for your help before
    Bmcc81
    Flash Designer / Web Developer
    -----------------------------------
    http://www.webinkgraphics.com

  8. #8
    Bmcc*81 bmcc81's Avatar
    Join Date
    Jul 2007
    Location
    Montreal
    Posts
    299

    Is there away to Make this start over?

    Hi Again,

    I was thinking about it and I want this to start again from the start once it goes through and sends back to the beginning.

    Is was thinking maybe delete var

    would I simply write that like;

    delete var i;


    I just tried this and it seems to work

    Code:
    var i:Number = 1; 
    
    function DoRandom() { 
    var target_x = home_x - content_mc["section_"+i]._x; 
    content_mc.slideTo( target_x, "0", 2 ); 
    i++; 
    
    if(i==6) var target_x = home_x-content_mc.section_0._x;
    	content_mc.slideTo(target_x,"0",2);
    	if(i==7) {
    		var i:Number = 1; 
    		var target_x = home_x - content_mc["section_"+i]._x; 
    content_mc.slideTo( target_x, "0", 2 ); 
    		}
    set [i]=1
    trace(i);
    }
    When I trace(i); it shows

    2
    3
    4
    5
    5
    6
    1
    BUT THEN
    8
    9
    10

    Which is not what I want.

    I want it to continue to be
    1
    2
    3
    4
    5
    6
    and that's it.

    How would I get his done?
    Bmcc81
    Flash Designer / Web Developer
    -----------------------------------
    http://www.webinkgraphics.com

  9. #9
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    PHP Code:
    var i:Number 1

    function 
    DoRandom() { 
    var 
    target_x home_x content_mc["section_"+i]._x
    content_mc.slideTotarget_x"0"); 
    i++; 

    if(
    i==6) {
    var 
    target_x home_x-content_mc.section_0._x;
    content_mc.slideTo(target_x,"0",2);
    }

    if(
    i==7) {
    1;         
    var 
    target_x home_x content_mc["section_"+i]._x
    content_mc.slideTotarget_x"0"); 
    }
    trace(i);
    }; 
    is the trace correct ?

  10. #10
    Bmcc*81 bmcc81's Avatar
    Join Date
    Jul 2007
    Location
    Montreal
    Posts
    299

    Horizontal Scrolling Banner - With 5 Buttons.

    Thanks for the help,

    Here's the code if anyone's interested.

    It may not be the prettiest, but she works.

    Code:
    import com.mosesSupposes.fuse.*;
    ZigoEngine.simpleSetup(Shortcuts);
    import mx.transitions.Tween;// IMPORTS MX.TRANSITION.TWEEN
    import mx.transitions.easing.*;// IMPORTS MX.TRANSITION.EASING
    
    
    _root.content_mc.section_0.gotoAndPlay(2);
    
    /////////////////////////////////////////////////////////////////////////////////////
    
    var i:Number = 1;
    
    function DoRandom() {
    var target_x = home_x - content_mc["section_"+i]._x;
    content_mc.slideTo( target_x, "0", 2 );
    content_mc["section_"+i].gotoAndPlay(2);
    i++;
    
    if(i==6) {
    	i=1;
    var target_x = home_x-content_mc.section_0._x;
    content_mc.slideTo(target_x,"0",2);
    }
    
    if(i==7) {
    i = 1;         
    var target_x = home_x - content_mc["section_"+i]._x;
    content_mc.slideTo( target_x, "0", 2 );
    
    }
    trace(i);
    if(i==1) var alphaT:Tween = new Tween(b_0, "_alpha", Regular.easeOut, 50, 70, 1, true);
    	if(i==2) var alphaT:Tween = new Tween(b_0, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	if(i==2) var alphaT:Tween = new Tween(b_1, "_alpha", Regular.easeOut, 50, 70, 1, true);
    	if(i==3) var alphaT:Tween = new Tween(b_1, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	if(i==3) var alphaT:Tween = new Tween(b_2, "_alpha", Regular.easeOut, 50, 70, 1, true);
    	if(i==4) var alphaT:Tween = new Tween(b_3, "_alpha", Regular.easeOut, 50, 70, 1, true);
    	if(i==4) var alphaT:Tween = new Tween(b_2, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	if(i==5) var alphaT:Tween = new Tween(b_4, "_alpha", Regular.easeOut, 50, 70, 1, true);
    	if(i==5) var alphaT:Tween = new Tween(b_3, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	if(i==6) var alphaT:Tween = new Tween(b_4, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	if(i==6) var alphaT:Tween = new Tween(b_0, "_alpha", Regular.easeOut, 50, 70, 1, true);
    	if(i==1) var alphaT:Tween = new Tween(b_4, "_alpha", Regular.easeOut, 50, 50, 1, true);
    };
    
    
    
    var intervalID = setInterval(DoRandom, 4000);
    
    /////////////////////////////////////////////////////////////////////////////////////
    			//				//  BUTTONS   //				// 
    /////////////////////////////////////////////////////////////////////////////////////
    
    var home_x = content_mc._x;
    
    b_0.onRelease = function() {
    	clearInterval(intervalID);
    	this.content_mc.section_1.gotoAndPlay(2);
    	var target_x = home_x-content_mc.section_0._x;
    	content_mc.slideTo(target_x,"0",2);
    	var alphaT:Tween = new Tween(b_0, "_alpha", Regular.easeOut, 50, 70, 1, true);
    
    	var alphaT:Tween = new Tween(b_1, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_2, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_3, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_4, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_5, "_alpha", Regular.easeOut, 50, 50, 1, true);
    
    };
    
    b_1.onRelease = function() {
    	clearInterval(intervalID);
    	this.content_mc.section_1.gotoAndPlay(2);
    	var target_x = home_x-content_mc.section_1._x;
    	content_mc.slideTo(target_x,"0",2);
    	var alphaT:Tween = new Tween(b_1, "_alpha", Regular.easeOut, 50, 70, 1, true);
    
    	var alphaT:Tween = new Tween(b_0, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_2, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_3, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_4, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_5, "_alpha", Regular.easeOut, 50, 50, 1, true);
    };
    
    b_2.onRelease = function() {
    	clearInterval(intervalID);
    	_root.content_mc.sections_2.gotoAndPlay(2);
    	var target_x = home_x-content_mc.section_2._x;
    	content_mc.slideTo(target_x,"0",2);
    	var alphaT:Tween = new Tween(b_2, "_alpha", Regular.easeOut, 50, 70, 1, true);
    
    	var alphaT:Tween = new Tween(b_0, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_1, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_3, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_4, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_5, "_alpha", Regular.easeOut, 50, 50, 1, true);
    };
    
    b_3.onRelease = function() {
    	clearInterval(intervalID);
    	_root.content_mc.sections_3.gotoAndPlay(2);
    	var target_x = home_x-content_mc.section_3._x;
    	content_mc.slideTo(target_x,"0",2);
    	var alphaT:Tween = new Tween(b_3, "_alpha", Regular.easeOut, 50, 70, 1, true);
    
    	var alphaT:Tween = new Tween(b_1, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_2, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_0, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_4, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_5, "_alpha", Regular.easeOut, 50, 50, 1, true);
    };
    
    b_4.onRelease = function() {
    	clearInterval(intervalID);
    	_root.content_mc.sections_4.gotoAndPlay(2);
    	var target_x = home_x-content_mc.section_4._x;
    	content_mc.slideTo(target_x,"0",2);
    	var alphaT:Tween = new Tween(b_4, "_alpha", Regular.easeOut, 50, 70, 1, true);
    
    	var alphaT:Tween = new Tween(b_1, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_2, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_3, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_0, "_alpha", Regular.easeOut, 50, 50, 1, true);
    	var alphaT:Tween = new Tween(b_5, "_alpha", Regular.easeOut, 50, 50, 1, true);
    };
    Bmcc81
    Flash Designer / Web Developer
    -----------------------------------
    http://www.webinkgraphics.com

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