A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Timer function

  1. #1
    Member
    Join Date
    Jun 2007
    Posts
    33

    Timer function

    Hi

    I have created a timer event,
    and I want its function onTimerp3 to call the function
    'Rollp3part2' into action, but I dont know how to initiate it:

    Any help will be a great help!
    matt

    function onTimerp3 ( e : TimerEvent ) : void {

    Rollp3part2

    }

    function Rollp3part2 ( e : MouseEvent ) {

    myTween = new Tween ( e.target, "x" , Back.easeIn, e.target.x, p3part2RollPoint.x , 1 , true );
    myTween = new Tween ( e.target, 'y' , Back.easeOut, e.target.y, p3part2RollPoint.y , 1 , true );

    }

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Since the second function is a mouse handler it's expecting a mouse event - override that with a default value so you can call it regularly:

    function Rollp3part2 ( e : MouseEvent = null ) {

  3. #3
    Member
    Join Date
    Jun 2007
    Posts
    33
    brilliant
    Is this a correct way to call the second function 'Rollp3part2' ?
    It is giving me an error report


    function onTimerp3 ( e : TimerEvent ) : void {

    Rollp3part2

    }

    thanks for the help

  4. #4
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    PHP Code:
    function onTimerp3 (e:TimerEvent):void{
        
    Rollp3part2();


  5. #5
    Member
    Join Date
    Jun 2007
    Posts
    33
    hi neznein

    thanks for the help so far!
    however i am getting this message

    'Cannot access a property or method of a null object reference'

    Im having difficulty finding the problem
    here is my code:

    function onTimerp3 ( e : TimerEvent ) : void {

    Rollp3part2();

    }

    function Rollp3part2 ( e : MouseEvent = null ) {


    myTween = new Tween ( e.target, "x" , Back.easeIn, e.target.x, p3part2RollPoint.x , 1 , true );
    myTween = new Tween ( e.target, 'y' , Back.easeOut, e.target.y, p3part2RollPoint.y , 1 , true );

    }


    cheers for helping

  6. #6
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Oh whoops - your second function is using data from the mouse Event - so if you ignore that (eg. call that function from a timer) there is no mouse data for it to tween to.

    You can either remove or rework those tweens or else you need to spoof a mouse event for whichever button you want to appear 'clicked' when that timer goes off...

  7. #7
    Member
    Join Date
    Jun 2007
    Posts
    33
    Ah.. the tween that I want is to move an object to another position on the stage,, any suggestions how I could spoof a mouse event to do this?

  8. #8
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    If you already know the object you can do it like so:
    PHP Code:
    function onTimerp3 (e:TimerEvent):void
    //    Rollp3part2(); 
        
    theObject.dispatchEvent(new MouseEvent(MouseEvent.CLICK));


  9. #9
    Member
    Join Date
    Jun 2007
    Posts
    33
    Brilliant ! cheers neznein
    that sorted out my problem
    matt

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