A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Why is as3.0 running worse then 2.0

  1. #1
    Member
    Join Date
    Jun 2008
    Posts
    30

    Question Why is as3.0 running worse then 2.0

    I made a simple flash in 2.0 where you are using a custom cursor and click in the blank screen. Where ever you click, it places a bullet hole and plays a gunshot sound. It runs perfectly fine and smoothly, but when I convert it to 3.0 it lags a little bit and sometimes misses a click. Why is it doing this?

    here's the code in 2.0

    Code:
    // Hide the mouse 
    Mouse.hide(); 
    // Set the Crosshair as your new mouse, set depth to 1 mill so the cursor will stay on top.
    attachMovie("crosshair", "crosshair", 1000000); 
    crosshair.onEnterFrame = function() { 
         this._x = _xmouse; 
         this._y = _ymouse; 
    }; 
    
    //attach the sound file
    var snd = new Sound();
    snd.attachSound("bang.wav");
    
    var a=1; //a is the depth, increment with each click
    // Place a bullet when the mouse is pressed as wel as play the sound
    function onMouseDown() { 
         startx = _xmouse; 
         starty = _ymouse; 
         attachMovie("bullet", "bullet", a, {_x:startx, _y:starty} );
         snd.start(); 
         a++;
    }
    ------------------------------------------------
    and here's the code in 3.0

    Code:
    // Hide the mouse 
    Mouse.hide(); 
    // Set the Crosshair as your new mouse 
    var crosshair:Crosshair = new Crosshair ();
    addChild(crosshair);
    stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
    function enterFrameHandler(event:Event):void 
    {
    crosshair.x = mouseX;
    crosshair.y = mouseY;
    }
    var snd:Bang = new Bang();
    
    //add a onclick event listener
    stage.addEventListener(MouseEvent.CLICK, onClick);
    // Place a bullet when the mouse is pressed 
    function onClick(event:MouseEvent) : void  
    { 
         var bullet:Bullet = new Bullet();
    	 addChild(bullet);
    	 bullet.x=mouseX;
    	 bullet.y=mouseY;
    	 //play bang
    	 snd.play();
    	 //to keep the custom cursor on top
    	 swapChildren(bullet, crosshair);
    
    }
    -----------------------
    is there any other way to keep the custom cursor always at the top level other then using swapChildren()? I noticed that it ran slightly better with it commented out but still slower then the 2.0.
    Last edited by dukes90; 06-04-2008 at 11:10 PM.

  2. #2
    Member
    Join Date
    Feb 2008
    Location
    Aylesbury
    Posts
    39
    Sorry buddy, the AS3 version worked fine for me! Maybe someone else can try it and see if they have a problem or not. It's a long shot, but maybe you had a browser open at the same time which has flash applications running. This machine I'm on uses XP, is 2.0Ghz, 1G ram. Maybe yours is an older computer....just trying to think of reasons. Nice code though!

  3. #3
    Member
    Join Date
    Jun 2008
    Posts
    30
    Thanks, I know the code works it's just that if you run the 2.0 version first then try the 3.0. I think you will notice that when you click multiple times quickly in the 3.0 the response is just a little bit slower. I'm running my on vista 2.2Ghz dual core with 2G ram, of course vista is a memory hog.

  4. #4
    Member
    Join Date
    Feb 2008
    Location
    Aylesbury
    Posts
    39
    Yes I see now. Ouch! That's surprising! Sorry I don't know.

  5. #5
    Member
    Join Date
    Sep 2007
    Location
    Corfu
    Posts
    42
    I think the problem is that you're adding a new child every time you click the mouse - eventually the whole thing will grind to a halt. You need some way of cleaning up redundant children once the bullet movie has finished.

  6. #6
    Member
    Join Date
    Feb 2008
    Location
    Aylesbury
    Posts
    39
    It don't think it'll be cos of too much memory use from using 'addChild', because even from the start the AS3 version is less quick and you can't click as often, compared to the AS2 version.

  7. #7
    Member
    Join Date
    Jun 2008
    Posts
    30
    exzactly Joe, I was just suprised because I thought that AS3 is supposed to be 10x faster. I'm just wondering if there's a better way to do this. Like i said a little bit of the lag is due to having to swap the child each time for the cursor to stay on top, but even with that commented out it's still slightly slower.

  8. #8
    Member
    Join Date
    Jun 2008
    Posts
    30
    ha this line of code fixed the lag

    event.updateAfterEvent();

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