|
-
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.
-
While I love to use Flash a lot, I have found that often times, it is easier to replicate a simpler effect such as this through DHTML instead of using Flash. It loads quicker, requires less resources on your clients' browser, and is often easier to pull off...
I'd reccomend using CSS, some DIVs, and some javascript (all together, DHTML) to reate an identical effect. If you need help with it, PM me (or if you're more independent, Google is your friend!)
-
thanks for the reply! and pm sent.
But if i did want to continue using flash instead, how would i fix this problem. Is it fixable? I remember sawing somewhere about if i add events i should remove them or it will hog up your browser over time, but I can't really remember because i was searching through video tutorials and i dont know where i saw it.
-
after looking at the code i dont think its because i am adding event listeners because i only have those when i click the button, but i went ahead and removed event listeners. here is the new code
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();
buttons.button1.removeEventListener(MouseEvent.CLICK, Button1Clicked);
}
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);
buttons.button2.removeEventListener(MouseEvent.CLICK, Button2Clicked);
}
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);
buttons.button3.removeEventListener(MouseEvent.CLICK, Button3Clicked);
}
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);
buttons.button4.removeEventListener(MouseEvent.CLICK, Button4Clicked);
}
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);
buttons.button5.removeEventListener(MouseEvent.CLICK, Button5Clicked);
}
//----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;
}
I am now assuming it is the tweening coding that is causing this to happen over time. Especially since i just combined a bunch of tips/googling/tutorials to make it and its probably badly coded. can someone please help me
-
can anyone please help me? I can't seem to solve this issue :[
-
Senior Member
well everytime a button is pressed you create a new variable for your tweens. while this isn't the source of your problem its not the best thing to be doing. uptop of script i'd write:
Code:
var variableName:Tween;
then in your button listener function were your using this tween. you can just write:
Code:
/* just made the inside of the function dots as
i'm not going to write it for you, you already
know what your putting in there.*/
variableName = new Tween(....);
i can't seem to find the actual source of your problem. anyways hopefully this has helped you to some degree.
Last edited by x-death; 07-29-2010 at 02:12 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|