PDA

View Full Version : Lag issues with photo viewer



XPugg
August 30th, 2007, 02:10 PM
Ok I'm new to AS3 but i am well versed in AS2 so making the conversions are proving a bit tricky, the issue i am having is I'm building a photo viewer style kiosk however if you leave it up in the browser for a few minutes it begins to lag and will continually get worse until clicking a button will cause it to crash (took about 10 minutes for that) but this is a large kiosk and very well could be viewed for that long and i have hit a wall trying to find out what it is causing the lag after a while. Please if someone could help out i would greatly appreciate it. Thank you very much


import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.events.Event;
import fl.transitions.TweenEvent;
var ticker_var :int = 11;
var clickyclicky_var=true;

//ON ENTER FRAME!!!!!!!!!!!!!!!!!!!!!!
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void {
//mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbypic_mc.lobbyslider_mc.x=lobbyX_var;

//ticker_var++;

/*if (ticker_var>13) {
ticker_var = 12;

}*/
trace(ticker_var);
//var lobbyX_var=mainmap_mc.lowerlevel_mc.popup_mc.lobby viewer_mc.lobbypic_mc.lobbyslider_mc.x;
//var lobbyXR_var=mainmap_mc.lowerlevel_mc.popup_mc.lobb yviewer_mc.lobbypic_mc.lobbyslider_mc.x;

//mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbypic_mc.lobbyslider_mc.x=lobbyX_var;
//lobbyX_var=mainmap_mc.lowerlevel_mc.popup_mc.lobby viewer_mc.lobbypic_mc.lobbyslider_mc.x;
//var lobbyX :Number=5;
//var lobbyleft:Tween = new Tween(mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewe r_mc.lobbypic_mc.lobbyslider_mc, "x", Regular.easeOut, mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbypic_mc.lobbyslider_mc.x,mainmap_mc.lowerlevel_ mc.popup_mc.lobbyviewer_mc.lobbypic_mc.lobbyslider _mc.x-200, 10, false);
//var lobbyright:Tween = new Tween(mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewe r_mc.lobbypic_mc.lobbyslider_mc, "x", Regular.easeOut, mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbypic_mc.lobbyslider_mc.x, mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbypic_mc.lobbyslider_mc.x+200, 10, false);
//trace(lobbyX_var);


if (ticker_var<11) {
clickyclicky_var=false;
}
if (ticker_var>11) {
clickyclicky_var=true;
}

if (clickyclicky_var==false) {
mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbyleft_btn.mouseEnabled=false;
mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbyright_btn.mouseEnabled=false;
ticker_var++;

//trace("off");
}
if (clickyclicky_var==true) {
mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbyleft_btn.mouseEnabled=true;
mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbyright_btn.mouseEnabled=true;
//trace("on");
}





/*var lobbyX :Number;*/
/*var lobbyX :Number=mainmap_mc.lowerlevel_mc.popup_mc.lobbyvie wer_mc.lobbypic_mc.lobbyslider_mc.x;
*/





//LEFT BUTTON SLIDER
mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbyleft_btn.addEventListener(MouseEvent.CLICK, leftlobbyclick);
function leftlobbyclick(Event:MouseEvent):void {
if ((mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc .lobbypic_mc.lobbyslider_mc.lobbysensorL_mc.hitTes tObject(mainmap_mc.lowerlevel_mc.popup_mc.lobbyvie wer_mc.lobbypic_mc.leftlobbystop_mc) == false)) {
mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbyleft_btn.mouseEnabled=false;

ticker_var=0;

//ticker_var++;
clickyclicky_var=false;

var lobbyleft:Tween = new Tween(mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewe r_mc.lobbypic_mc.lobbyslider_mc, "x", Regular.easeOut, mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbypic_mc.lobbyslider_mc.x,mainmap_mc.lowerlevel_ mc.popup_mc.lobbyviewer_mc.lobbypic_mc.lobbyslider _mc.x-200, 10, false);

lobbyleft.start();

//lobbyleft.stop();
}
}
//RIGHT BUTTON SLIDER
mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbyright_btn.addEventListener(MouseEvent.CLICK, rightlobbyclick);
function rightlobbyclick(Event:MouseEvent):void {
if ((mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc .lobbypic_mc.lobbyslider_mc.lobbysensorR_mc.hitTes tObject(mainmap_mc.lowerlevel_mc.popup_mc.lobbyvie wer_mc.lobbypic_mc.rightlobbystop_mc) == false)) {
mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbyright_btn.mouseEnabled=false;

ticker_var=0;
clickyclicky_var=false;

var lobbyright:Tween = new Tween(mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewe r_mc.lobbypic_mc.lobbyslider_mc, "x", Regular.easeOut, mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbypic_mc.lobbyslider_mc.x, mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbypic_mc.lobbyslider_mc.x+200, 10, false);

lobbyright.start();
//lobbyright.stop();
}
}


/*lobbyleft.addEventListener(TweenEvent.MOTION_FINI SH,handleResetL);
function handleResetL(Event:TweenEvent):void {
//lobbyX_var = mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbypic_mc.lobbyslider_mc.x;

trace("left stop");
}
lobbyright.addEventListener(TweenEvent.MOTION_FINI SH,handleResetR);
function handleResetR(Event:TweenEvent):void {
//lobbyX_var = mainmap_mc.lowerlevel_mc.popup_mc.lobbyviewer_mc.l obbypic_mc.lobbyslider_mc.x;

trace("right stop");
}*/


mainmap_mc.lowerlevel_mc.lobby_btn.addEventListene r(MouseEvent.CLICK, lobbyClick);
function lobbyClick(Event:MouseEvent):void {
//trace("lobby click");
mainmap_mc.lowerlevel_mc.popup_mc.x=88;
mainmap_mc.lowerlevel_mc.popup_mc.y=-67.8;
}

mainmap_mc.lowerlevel_mc.popup_mc.lobbyclose_btn.a ddEventListener(MouseEvent.CLICK, lobbeyloseClick);
function lobbeyloseClick(Event:MouseEvent):void {
mainmap_mc.lowerlevel_mc.popup_mc.x=789;
mainmap_mc.lowerlevel_mc.popup_mc.y=-470;
}




mainmap_mc.lowerlevel_mc.popup_mc.lobbydrag_btn.ad dEventListener(MouseEvent.MOUSE_DOWN, lobbyDrag);
function lobbyDrag(Event:MouseEvent):void {
/*trace("draging");*/
mainmap_mc.lowerlevel_mc.popup_mc.startDrag(false) ;
}


mainmap_mc.lowerlevel_mc.popup_mc.lobbydrag_btn.ad dEventListener(MouseEvent.MOUSE_UP, lobbyDragstop);
function lobbyDragstop(Event:MouseEvent):void {
mainmap_mc.lowerlevel_mc.popup_mc.stopDrag();
}
}
stop();

butcherBaker
August 30th, 2007, 04:55 PM
without reading all of that, I'm guessing that it has something to do with the fact that you are creating 2 tween objects per frame. when I first started messing with tweens, I was applying them in an onEnterFrame (AS2) and it seemed to work for a few minutes then it go so bogged down it was ridiculous.
The Tween has it's own internal EnterFrame function.

XPugg
September 5th, 2007, 01:37 PM
I though about that and tried it with them outside the onEnterFrame and i still got bad lag issues though it didn't take as long that way it wasn't very much of an improvement really

cesig
September 5th, 2007, 03:24 PM
You're creating several listeners on every frame. And they're not weak-referenced, either, so ithey're not going to get GCd. This is no good. And it's probably why your app bogs down. I'm sure the memory footprint after a few minutes is huge.

You should only need to add a listener once. If you need to do it more than once, I can't imagine that doing it on EVERY frame is the right way to do it.

Also, there are a few places where you could optimize the if statements, but that's not the cause of the slowdowns.

Also, it's generally considered bad practice to name functions (onEnterFrame)
after reserved words (I know it's only reserved in AS2, but still).

Hope that helps!

Edit: Alllllllllso, you're declaring functions multiple times. Those need to be pulled out of the onEnterFrame. That's bad, too. You only need to do that once for each function.

XPugg
September 5th, 2007, 03:40 PM
ill give it a shot but lately i was thinking about scraping it and going with a dynamic loading fading version using an array to lode in the pictures (because i just learned ill have over 200 in this project) and even with those alone i feel it could bog down though using the Loader.load and array's in AS3 together is still above my grasps. I guess I'm not adapting as fast as I would like to AS3 and if anyone has any suggestions i would love the help. and thank you guys for the help so far! :kir:

XPugg
September 5th, 2007, 03:44 PM
I have a working version of this in AS2 but i need to convert it to AS3 and am struggling with it!

cesig
September 5th, 2007, 03:59 PM
I have a working version of this in AS2 but i need to convert it to AS3 and am struggling with it!

I hear you. That's how I started with AS3 - by converting AS2 code. In the end, I just re-wrote it from scratch. I've found that the structure changes enough between 2 and 3 that the overall code structure is AS2-like, not just the syntax.

If that makes any sense.

XPugg
September 5th, 2007, 04:07 PM
yea been converting code for a bit now I'm just a big (and complex) code junkie and its frustrating when i cant get something like this granted it not simple but still no too difficult. check my website if you wanna see what i was doing in AS2 and i cant seem to convert anything easily or even get the code right to re work it. thank you for the advice i guess i just got a few work day of staring at the screen ahead of me. :mario::luigi:

cesig
September 5th, 2007, 04:26 PM
There are a few major things that have changed from AS2 to AS3 (display list, event model, class-centric code), but a lot of learning AS3 is just getting the new syntax down.

It didn't take me as long as I was expecting to get comfortable with AS3. Hopefully it'll be the same for you. :yoshi:

XPugg
September 5th, 2007, 04:39 PM
i hope so, I'm working on it as i speak. I've been at it since 9 this morning! Its getting there just the new syntax is a pain as i was so used to the old one but yea gotta move on with the times and it's not too different thankfully, just different enough to confuse the hell out of me! I do appritiate all the help your giving and even the words of encouragement and if ya need anything let me know, but I'm gonna go rip my eyes out and stare at this code more! :link: