A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Challenge: Can this AS2 banner script be looped?

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    2

    Challenge: Can this AS2 banner script be looped?

    I am pulling my hair out trying to figure this out. Is it possible to make this script loop 3 times instead of 1?
    Code:
    stop();
    /* Functions for banners*/
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    import TextField.StyleSheet;
    
    createEmptyMovieClip("headline", 0);
    createEmptyMovieClip("text1", 1);
    createEmptyMovieClip("text2", 2);
    createEmptyMovieClip("callToAction", 5);
    createEmptyMovieClip("logos", 6);
    
    var myCSS:StyleSheet = new StyleSheet();
    myCSS.setStyle("prices1", {fontSize:'46px', letterSpacing:'-2px', fontFamily:'bodyMedium', color:'#ffffff'});
    myCSS.setStyle("mytaxes1", {fontSize:'10px', fontFamily:'bodyMedium', textIndent:'10px', color:'#ffffff'});
    myCSS.setStyle("prices2", {fontSize:'46px', letterSpacing:'-2px', fontFamily:'bodyMedium', color:'#ffffff'});
    myCSS.setStyle("mytaxes2", {fontSize:'10px', fontFamily:'bodyMedium', textIndent:'10px', color:'#ffffff'});
    
    function logoPlace(){
    	logos.lineStyle(1,0x830000,0);
    	logos.moveTo(0,497);
    	logos.lineTo(0,119);
    	logos.lineTo(599,119);
    	logos.lineTo(599,497);
    	logos.lineTo(0,497);
    	logos.attachMovie("wviLogo", "wvi_logo", logos.getNextHighestDepth());
    	
    	if(coop == 0) {
    		logos.wvi_logo._x = (Stage.width - logos.wvi_logo._width) / 2;
    		logos.wvi_logo._y = ((Stage.height + 497) - logos.wvi_logo._height) / 2;
    		
    	} else {
    		logos.attachMovie("coopLogo", "logo", logos.getNextHighestDepth());
    		logos.logo._x = (Stage.width - logos.logo._width) / 2;
    		logos.wvi_logo._x = (Stage.width - logos.wvi_logo._width) / 2;
    
    		logos.logo._y = (Stage.height - logos.logo._height) / 2 + ((497 + (51 / 2)) - (Stage.height / 2));	
    		logos.wvi_logo._y = (Stage.height - logos.wvi_logo._height) / 2 + (497 + logos.wvi_logo._height - (Stage.height / 2)) + 51;
    	}
    	
    }
    
    /* This function creates the header text and slides the header in */
    function headerSlide() {
    	headline.lineStyle(1,0xffffff,0);
    	headline.moveTo(0,0);
    	headline.lineTo(0,497);
    	headline.lineTo(119,497);
    	headline.lineTo(119,0);
    	headline.lineTo(0,0);
    	
    	headline.createTextField("headline", headline.getNextHighestDepth(), 0, 0, 103, 109);
    	//headline.headline.border = true;
    	headline.headline.wordWrap = true;
    	headline.headline.multiline = true;
    	headline.headline.autoSize = true;
    	headline.headline.selectable = false;
    	headline.headline.selectable = false;
    	headline.headline.html = true;
    	headline.headline.embedFonts = true;
    	
    	headline.headline.htmlText = "<textformat leading='-3'><p align='center'><font face='body' size='16' color='#ffffff'>";
    	headline.headline.htmlText += header;
    	headline.headline.htmlText += "</font></br>";
    
    	headline.headline._y = (headline._height - headline.headline._height) / 2;
    	headline.headline._x = (Stage.width - headline.headline._width) / 2;
    	
    }
    function text1Slide() {
    	text1.lineStyle(1,0xffffff,0);
    	text1.moveTo(0,0);
    	text1.lineTo(0,480);
    	text1.lineTo(119,480);
    	text1.lineTo(119,0);
    	text1.lineTo(0,0);
    	
    	text1.createTextField("text1", text1.getNextHighestDepth(), 0, 0, 140, 109);
    	//headline.headline.border = true;
    	text1.text1.wordWrap = true;
    	text1.text1.multiline = true;
    	text1.text1.autoSize = true;
    	text1.text1.selectable = false;
    	text1.text1.selectable = false;
    	text1.text1.html = true;
    	text1.text1.embedFonts = true;
    	
    	text1.text1.htmlText = "<textformat leading='-3'><p align='center'><font face='body' size='16' color='#ffffff'>";
    	text1.text1.htmlText += text_1;
    	text1.text1.htmlText += "</font></br>";
    
    	text1.text1._y = ((text1._height - text1.text1._height) / 2) + 130;
    	text1.text1._x = (Stage.width - text1.text1._width) / 2;
    
    }
    
    function text2Slide() {
    	text2.lineStyle(1,0xffffff,0);
    	text2.moveTo(0,0);
    	text2.lineTo(0,497);
    	text2.lineTo(119,497);
    	text2.lineTo(119,0);
    	text2.lineTo(0,0);
    	
    	text2.createTextField("text2", text2.getNextHighestDepth(), 0, 0, 120, 109);
    	//headline.headline.border = true;
    	text2.text2.wordWrap = true;
    	text2.text2.multiline = true;
    	text2.text2.autoSize = true;
    	text2.text2.selectable = false;
    	text2.text2.selectable = false;
    	text2.text2.html = true;
    	text2.text2.embedFonts = true;
    	
    	text2.text2.htmlText = "<textformat leading='-3'><p align='center'><font face='body' size='16' color='#ffffff'>";
    	text2.text2.htmlText += text_2;
    	text2.text2.htmlText += "</font></br>";
    
    	text2.text2._y = ((text2._height - text2.text2._height) / 2) + 89;
    	text2.text2._x = (Stage.width - text2.text2._width) / 2;
    
    }
    
    function callToActionSlide() {
    	callToAction.lineStyle(1,0xffffff,0);
    	callToAction.moveTo(0,0);
    	callToAction.lineTo(0,497);
    	callToAction.lineTo(119,497);
    	callToAction.lineTo(119,0);
    	callToAction.lineTo(0,0);
    	
    	callToAction.createTextField("callToAction", callToAction.getNextHighestDepth(), 0, 0, 140, 109);
    	//headline.headline.border = true;
    	callToAction.callToAction.wordWrap = true;
    	callToAction.callToAction.multiline = true;
    	callToAction.callToAction.autoSize = true;
    	callToAction.callToAction.selectable = false;
    	callToAction.callToAction.selectable = false;
    	callToAction.callToAction.html = true;
    	callToAction.callToAction.embedFonts = true;
    	
    	callToAction.callToAction.htmlText = "<textformat leading='-3'><p align='center'><font face='body' size='15' color='#ffffff'>";
    	callToAction.callToAction.htmlText += cta;
    	callToAction.callToAction.htmlText += "</font></br>";
    
    	callToAction.callToAction._y = ((callToAction._height - callToAction.callToAction._height) / 2) + 89;
    	callToAction.callToAction._x = (Stage.width - callToAction.callToAction._width) / 2;
    
    }
    
    /* runtime1 */
    function runFirstSlideIn() {
    	headerSlide();
    	var myalphaHeader:Tween = new Tween(headline, "_alpha", Strong.easeOut, 0, 100, 1, true);
    
    }
    function runFirstSlideOut() {
    	var myalphaHeader:Tween = new Tween(headline, "_alpha", Strong.easeOut, 100, 0, 1, true); 
    }
    function imageSlide() {
    	text1Slide();
    	var myfirstPrice:Tween = new Tween(text1, "_alpha", Strong.easeOut, 0, 100, 1, true);
    }
    function slideOneOut(){
    	var myfirstPrice:Tween = new Tween(text1, "_alpha", Strong.easeOut, 100, 0, 1, true);
    	 
    }
    function slideImageIn(){
    	var myTween1:Tween = new Tween(imagebloc, "_y", Strong.easeOut, 0, 194, 1, true);
    }
    function slideTwoIn(){
    	text2Slide();
    	var myfirstPrice:Tween = new Tween(text2, "_alpha", Strong.easeOut, 0, 100, 1, true); 
    }
    function slideTwoOut(){
    	var mysecondPrice:Tween = new Tween(text2, "_alpha", Strong.easeOut, 100, 0, 1, true);
    }
    function slideCallToAction(){
    	callToActionSlide();
    	var mylastSlide:Tween = new Tween(callToAction, "_alpha", Strong.easeOut, 0, 100, 1, true);	 
    }
    
    /* timer function */
    var xy = 0;
    var duration = 1000;
    
    logoPlace();
    
    function runBanner(){
    	switch (noSlides) {
    		case 3:	switch (xy) {
    					case 0: runFirstSlideIn();
    							break;		
    					case 4:	runFirstSlideOut();
    							slideImageIn();
    							imageSlide();
    							break;
    					case 15:slideOneOut();
    							slideCallToAction();
    							clearInterval(myInterval);
    							break;
    				}
    				break;
    		
    		case 4:	switch (xy) {
    					case 0: runFirstSlideIn();
    							break;		
    					case 5:	runFirstSlideOut();
    							slideImageIn();
    							imageSlide();
    							break;
    					case 10: slideOneOut();
    							slideTwoIn();
    							break;
    					case 15:slideTwoOut();
    							slideCallToAction();
    							clearInterval(myInterval);
    							break;
    				}
    				break;
    	}
    	//trace (xy);
    	xy++;
    }	
    
    myInterval = setInterval(runBanner, duration);

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    I didnt test it or anything..

    but it seems to just be called on an interval()...

    just call it again.. or do a check to see if a variable has been incremented 3 times before clearing the interval

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    2
    So it would be something within the final line of code? myInterval = setInterval(runBanner, duration);

    I am not really familiar with intervals but I will see if I can dig something up online.

    Thankyou for your help!

  4. #4
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    Hi

    A setInterval(); will run/execute every XX seconds (second parameter) until it is cancelled..

    IN both your case 3 & 4 statements.. you CLEAR/STOP the interval from happening again..


    depending on the desired results....

    you can either call it again..

    or in the case statements.. do a check on a counter variable to says nope.. not 3 times yet.. play again...etc.. and IF has playd 3 times.. then clear it as you are now..

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