A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: AS3 My flash object is making browser unresponsive overtime

Threaded View

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    7

    AS3 My flash object is making browser unresponsive overtime

    Hey guys, this is my first flash project. It is a website for my dad and i decided to take this opportunity to learn flash. I made the nav bar using a tutorial i found from youtube and the code is this
    Code:
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.net.URLRequest;
    
    var timer:Timer = new Timer(25);
    timer.addEventListener(TimerEvent.TIMER, followF);
    timer.start();
    
    function followF(e:Event):void{
    	stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseF);
    }
    
    function mouseF(e:MouseEvent):void{
    	master_mc.glow_mc.x = stage.mouseX-40;
    	addEventListener(MouseEvent.MOUSE_MOVE, updateF);
    	if(mouseX<=40){
    		master_mc.glow_mc.x = 0;
    	} else if(mouseX>=360){
    		master_mc.glow_mc.x = 320;
    	}
    }
    
    function updateF(e:MouseEvent):void{
    	e.updateAfterEvent();
    }
    
    //------button code
    master_mc.addEventListener(MouseEvent.MOUSE_DOWN, glowStickF);
    
    function glowStickF(e:MouseEvent):void{
    	master_mc.glow_mc.x = e.target.x;
    }
    
    //------links
    master_mc.home.addEventListener(MouseEvent.CLICK, homeF);
    master_mc.about_us.addEventListener(MouseEvent.CLICK, about_usF);
    master_mc.services.addEventListener(MouseEvent.CLICK, servicesF);
    master_mc.contact_us.addEventListener(MouseEvent.CLICK, contact_usF);
    master_mc.specials.addEventListener(MouseEvent.CLICK, specialsF);
    
    function homeF(e:MouseEvent):void{
    	var homeLink:URLRequest = new URLRequest("http://www.renewal-dayspa.com/goldstar/index.html");
    	navigateToURL(homeLink, "_self");
    }
    
    function about_usF(e:MouseEvent):void{
    	var about_usLink:URLRequest = new URLRequest("http://www.renewal-dayspa.com/goldstar/aboutus.html");
    	navigateToURL(about_usLink, "_self");
    }
    
    function servicesF(e:MouseEvent):void{
    	var servicesLink:URLRequest = new URLRequest("http://www.renewal-dayspa.com/goldstar/services.html");
    	navigateToURL(servicesLink, "_self");
    }
    
    function contact_usF(e:MouseEvent):void{
    	var contact_usLink:URLRequest = new URLRequest("http://www.renewal-dayspa.com/goldstar/contact.html");
    	navigateToURL(contact_usLink, "_self");
    }
    
    function specialsF(e:MouseEvent):void{
    	var specialsLink:URLRequest = new URLRequest("http://www.renewal-dayspa.com/goldstar/specials.html");
    	navigateToURL(specialsLink, "_self");
    }
    The next thing is the slideshow at the bottom, which i used what i learned from the navbar project and some trial and error coding/googling to make. with this code here
    Code:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import flash.events.MouseEvent;
    
    var img1FadeIn:Tween = new Tween(img1, "alpha", Strong.easeOut, 0, 1, 5, true);
    stop();
    var slideTimer;
    slideTimer = setInterval(nextslide, 10000);
    var frame = Number;
    function nextslide()
    {
    	frame = currentFrame;
    	if(frame == 1)
    	{
    		gotoAndStop(2);
    		var img2FadeIn:Tween = new Tween(img2, "alpha", Strong.easeOut, 0, 1, 5, true);
    	}
    	else if(frame == 2)
    	{
    		gotoAndStop(3);
    		var img3FadeIn:Tween = new Tween(img3, "alpha", Strong.easeOut, 0, 1, 5, true);
    	}
    	else if (frame == 3)
    	{
    		gotoAndStop(4);
    		var img4FadeIn:Tween = new Tween(img4, "alpha", Strong.easeOut, 0, 1, 5, true);
    	}
    	else if (frame == 4)
    	{
    		gotoAndStop(5);
    		var img5FadeIn:Tween = new Tween(img5, "alpha", Strong.easeOut, 0, 1, 5, true);
    	}
    	else if (frame == 5)
    	{
    		gotoAndStop(1);
    		img1FadeIn.start();
    	}
    }
    //---- BUTTONS
    buttons.button1.addEventListener(MouseEvent.CLICK, Button1Clicked);
    buttons.button2.addEventListener(MouseEvent.CLICK, Button2Clicked);
    buttons.button3.addEventListener(MouseEvent.CLICK, Button3Clicked);
    buttons.button4.addEventListener(MouseEvent.CLICK, Button4Clicked);
    buttons.button5.addEventListener(MouseEvent.CLICK, Button5Clicked);
    
    function Button1Clicked(e:MouseEvent):void 
    	{
    		clearInterval(slideTimer);
    		slideTimer = setInterval(nextslide, 10000);
    		gotoAndStop(1);
    		img1FadeIn.start();
    	}
    
    function Button2Clicked(e:MouseEvent):void 
    	{
    		clearInterval(slideTimer);
    		slideTimer = setInterval(nextslide, 10000);
    		gotoAndStop(2);
    		var img2FadeIn:Tween = new Tween(img2, "alpha", Strong.easeOut, 0, 1, 5, true);
    	}
    	
    function Button3Clicked(e:MouseEvent):void 
    	{
    		clearInterval(slideTimer);
    		slideTimer = setInterval(nextslide, 10000);
    		gotoAndStop(3);
    		var img3FadeIn:Tween = new Tween(img3, "alpha", Strong.easeOut, 0, 1, 5, true);
    	}
    	
    function Button4Clicked(e:MouseEvent):void 
    	{
    		clearInterval(slideTimer);
    		slideTimer = setInterval(nextslide, 10000);
    		gotoAndStop(4);
    		var img4FadeIn:Tween = new Tween(img4, "alpha", Strong.easeOut, 0, 1, 5, true);
    	}
    	
    function Button5Clicked(e:MouseEvent):void 
    	{
    		clearInterval(slideTimer);
    		slideTimer = setInterval(nextslide, 10000);
    		gotoAndStop(5);
    		var img5FadeIn:Tween = new Tween(img5, "alpha", Strong.easeOut, 0, 1, 5, true);
    	}
    	
    	
    	
    	
    //----SLIDER	
    var timer:Timer = new Timer(25);
    timer.addEventListener(TimerEvent.TIMER, followF);
    timer.start();
    
    function followF(e:TimerEvent):void{
    	stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseF);
    }
    
    function mouseF(e:MouseEvent):void{
    	addEventListener(MouseEvent.MOUSE_MOVE, updateF);
    	if(mouseY>=236){
    		buttons.slidestick.x = stage.mouseX-205;
    		if(mouseX<=205){
    			buttons.slidestick.x = 0;
    		} else if(mouseX>=715){
    			buttons.slidestick.x = 530;
    		}
    	}
    }
    
    function updateF(e:MouseEvent):void{
    	e.updateAfterEvent();
    }
    
    buttons.addEventListener(MouseEvent.MOUSE_DOWN, glowStickF);
    
    function glowStickF(e:MouseEvent):void{
    	buttons.slidestick.x = e.target.x;
    }
    here is the webpage http://www.renewal-dayspa.com/goldstar/index.html

    THE PROBLEM: If i leave the page with the flash on and say forget about it. Eventually my computer gets really lagging and my browser becomes unresponsive which i then have to force quit. I'm assuming this is because of the slideshow because for the navbar i followed a tutorial step by step. I really don't have a clue why its causing the browser to crash, my guess is because it keeps adding events? someone please help me!!!! thanks :]

    Another issue that i have found out: I left the page on overtime and was monitoring the activity and overtime i saw that the slide show tweening began to freeze/stutter. Some pictures didnt fade in all the way, some didnt fade out all the way etc. I am assuming shortly after this is when the browser begins to become unresponsive.
    Last edited by longwang; 07-13-2010 at 03:43 AM.

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