A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: [RESOLVED] tweening problem

  1. #1
    Member
    Join Date
    Jun 2009
    Posts
    75

    resolved [RESOLVED] tweening problem

    Hi
    I am making a simple image gallery, basically their are 5 pictures positioned on the stage and when one is clicked it centers itself on the screen then expands its height and width to fill the stage, most of the time this works fine but for some reason the very first time an image is clicked it doesn't center itself vertically only horizontally, I'm sure this must be a simple problem i just can't pick it up.
    here is my code:
    PHP Code:
    pic1.addEventListener(MouseEvent.MOUSE_DOWNmovePic);
    pic2.addEventListener(MouseEvent.MOUSE_DOWNmovePic);
    pic3.addEventListener(MouseEvent.MOUSE_DOWNmovePic);
    pic4.addEventListener(MouseEvent.MOUSE_DOWNmovePic);
    pic5.addEventListener(MouseEvent.MOUSE_DOWNmovePic);


    var 
    myTimer:Timer = new Timer(10001);
    myTimer.addEventListener(TimerEvent.TIMERgrowWidth);
    var 
    myTimer2:Timer = new Timer(10001);
    myTimer2.addEventListener(TimerEvent.TIMERgrowHeight);

    var 
    lisTimer:Timer = new Timer(1500);
    lisTimer.addEventListener(TimerEvent.TIMERaddlistener);

    var 
    lisTimer2:Timer = new Timer(2500);
    lisTimer2.addEventListener(TimerEvent.TIMERaddlistener2);

    function 
    addlistener(e:TimerEvent):void{
        
    mc.addEventListener(MouseEvent.MOUSE_DOWNclosePic);
            
    }
    function 
    addlistener2(e:TimerEvent):void{
        
    mc.addEventListener(MouseEvent.MOUSE_DOWNmovePic);
        
    }
    var 
    mc:Object;
    var 
    oX:Number;
    var 
    oY:Number;
    var 
    oW:Number;
    var 
    oH:Number;

    function 
    movePic(evt:MouseEvent):void{
        if(
    lisTimer2.running){
        
    lisTimer2.stop();
        }
        
    mc evt.target;
        
    mc.removeEventListener(MouseEvent.MOUSE_DOWNmovePic);
        
    oX mc.x;
        
    oY mc.y;
        
    oW mc.width;
        
    oH mc.height;
        
    mc.parent.setChildIndex(mcmc.parent.numChildren-1);
        
    centerPic();
        
        
    myTimer.start();
        
        }

    function 
    growHeight(evt:TimerEvent):void{
        
    import fl.transitions.Tween;
        
    import fl.transitions.easing.*;
        var 
    myTweenHeight:Tween = new Tween(mc"height"Strong.easeOutmc.heightstage.stageHeight3true);
        
        
    lisTimer.start();
        
        }
    function 
    growWidth(evt:TimerEvent):void{
        
    import fl.transitions.Tween;
        
    import fl.transitions.easing.*;
        
        var 
    myTweenWidth:Tween = new Tween(mc"width"Strong.easeOutmc.widthstage.stageWidth3true);
        
            
    myTimer2.start();
            
    myTimer.stop();
        
        }
    var 
    stagew:Number = (stage.stageWidth/2);
    var 
    stageh:Number =(stage.stageHeight/2);
        
    function 
    centerPic():void{
        
    import fl.transitions.Tween;
        
    import fl.transitions.easing.*;
        
        var 
    myTweenX:Tween = new Tween(mc"x"Strong.easeOutmc.x,stagew 2true);
        var 
    myTweenY:Tween = new Tween(mc"y"Strong.easeOutmc.y,stageh 2true);

        }
    function 
    closePic(evt:MouseEvent):void{
        
        
    lisTimer.stop();
        
        
    mc.removeEventListener(MouseEvent.MOUSE_DOWNclosePic);
        
    import fl.transitions.Tween;
        
    import fl.transitions.easing.*;
        var 
    myTweenWidth:Tween = new Tween(mc"width"Strong.easeInmc.widthoW2true);
        var 
    myTweenHeight:Tween = new Tween(mc"height"Strong.easeInmc.heightoH2true);
        var 
    myTweenX:Tween = new Tween(mc"x"Strong.easeInstagewoX2true);
        var 
    myTweenY:Tween = new Tween(mc"y"Strong.easeInstagehoY2true);
        
        
    lisTimer2.start();
        
        } 

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Try adding a trace right after you set stagew and stagey:

    PHP Code:
    var stagew:Number = (stage.stageWidth/2);
    var 
    stageh:Number =(stage.stageHeight/2); 
    trace("stagew:"stagew"\nstageh:"stageh); 
    If you get null its because you are recording those values before your main object has been added to the stage. There is no longer a global Stage object like in as2. Instead each descendant of DisplayObject has a .stage property but only when the object is actually on a display list.

    The way to ensure there's a stage property to read is to set up a listener for ADDED_TO_STAGE where you handler calls and init function that starts up your movie.

    PHP Code:
    addEventListener(Event.ADDED_TO_STAGEonAdded);

    function 
    onAdded(e:Event):void{
      
    removeEventListener(Event.ADDED_TO_STAGEonAdded);
      
    init();
    }

    function 
    init():void{
      
    //everything else


  3. #3
    Senior Member
    Join Date
    Jul 2001
    Location
    San Jose California
    Posts
    144
    Jbard - I noticed when creating dynamic boarders that preview (ctrl+enter) will short the height value of the stage. For example if the stage height was 200px the boarder would show up as 100px in preview. Viewing the file by double clicking on the swf or putting it in a page things look normal.

    Could this preview bug be the issue?

  4. #4
    Member
    Join Date
    Jun 2009
    Posts
    75
    hmmm, well i seem to have the opposite problem. if i use (ctrl + enter) everything works fine. But when i use the swf thats when i get my problems.

  5. #5
    Senior Member
    Join Date
    Jul 2001
    Location
    San Jose California
    Posts
    144
    Have you tried what jAQUAN mentioned? Drop a dynamic text box onto the stage and then see what it's spitting out when the file is embedded into your html.

    I noticed that AS3 stage calls have problems if you are exporting as Flash Player 9. If that is the case you might consider hard coding your stage values if it's only the images that are what differs in size.

  6. #6
    Member
    Join Date
    Jun 2009
    Posts
    75
    ok this is really wierd, i just added the trace values and they would always appear as the correct number and everything would work fine, then i tried in my swf and i would still get the error. so i added two text fields which displayed the stagew and stageh properties and i havent got the error in my swf. then i took the text fields away and got the error straight away. i dont know how these text fields could stop the error but they appear to be doing so.

  7. #7
    Senior Member
    Join Date
    Jul 2001
    Location
    San Jose California
    Posts
    144
    wacky

  8. #8
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    what packages are you importing ?

  9. #9
    Senior Member
    Join Date
    Jul 2001
    Location
    San Jose California
    Posts
    144
    This seems to work for my stage object problem. Maybe it might work for yours.

    PHP Code:
    var bugFix = function(){
    // do stuff
    // make sure stage variables are in here as well
    };
    setTimeout(bugFix,1); 

  10. #10
    Member
    Join Date
    Jun 2009
    Posts
    75
    at the moment i have this writen in the main time line so the only things i import are these:

    import fl.transitions.Tween;
    import fl.transitions.easing.*;

  11. #11
    Senior Member
    Join Date
    Jul 2001
    Location
    San Jose California
    Posts
    144
    Quote Originally Posted by Jbard View Post
    ok this is really wierd, i just added the trace values and they would always appear as the correct number and everything would work fine, then i tried in my swf and i would still get the error. so i added two text fields which displayed the stagew and stageh properties and i havent got the error in my swf. then i took the text fields away and got the error straight away. i dont know how these text fields could stop the error but they appear to be doing so.
    It's possible the order of execution is screwing things up. The text fields may offset that. How did the setTimeout() work?

  12. #12
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    its definitely an order of operations thing. I wouldnt be surprised if your two vars , stagew and stageh , do not have values yet , at the time in which your timer starts. You are declaring them way down into your code. Try declaring and instantiating them as the very first thing you do.

  13. #13
    Member
    Join Date
    Jun 2009
    Posts
    75

    Wink

    Yes i declared my variables at the top of my code and added a settimeout function and everything seems to be working fine.
    Thank you very much for all your help i really appreciate it

  14. #14
    Senior Member
    Join Date
    Jul 2001
    Location
    San Jose California
    Posts
    144
    nice!

  15. #15
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    ADDED_TO_STAGE events were creates to avoid having to do just that.

  16. #16
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    cool , mark your thread as resolved

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