A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: How to trigger a button's over state, without the mouse, for a specified time

  1. #1
    Member
    Join Date
    Sep 2010
    Posts
    41

    How to trigger a button's over state, without the mouse, for a specified time

    I am trying to figure out how to trigger a button's over state (i.e. play the over state movie clip for about 4 seconds and then return to the up state) without the mouse event.

    The playing of the movie clip would occur when an Action Script cue point in an flv was reached. I think I have the right code for the cue point handling, but have no idea how to specify the over state of a button, or how to tell it to play for a specified time and then return to it's up state.

    Is this possible?

    I have added the cue points and got them to trace their names in the output window.
    Here is the code I would use for the cue point event handling, minus the then statement to tell the movie clip to play (see where it says "what goes here?" below):

    video.addEventListener(MetadataEvent.CUE_POINT, fl_CuePointHandler);

    function fl_CuePointHandler(event:MetadataEvent):void
    {
    if (event.info.name == "part1"){
    what goes here?
    }
    if...etc...
    }

    Another possible way to do it would be to add movie clips that are the same as the button over state and add them to the stage with visible = false until the cue point is reached. In that case I know how to tell them:
    movieclip.visible = true;
    movieclip.play();

    but how would I tell it to play for 4 seconds and then become invisible again?

  2. #2
    AS2 intolerant person
    Join Date
    Jan 2009
    Location
    Swansea
    Posts
    352
    i know you can manually fire the mouse over event, like this:

    actionscript Code:
    public function constructor() {
        button.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
    }


    // called upon mouse over event dispatch
    private function onMouseOver(e:MouseEvent):void {

    }

    function fl_CuePointHandler(event:MetadataEvent):void
    {
        if (event.info.name == "part1"){
            button.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OVER));
        }
        if...etc...
    }

    this is the method used for custom, actionscript or custom timeline driven animations, and it is the most modern technique.

    i havent done what you are trying to do, but looking at the fl.controls.button api docs, i did find this function:

    http://www.adobe.com/livedocs/flash/...useState%28%29

    actionscript Code:
    setMouseState(state:String);

    im guessing you use it like this:

    actionscript Code:
    button.setMouseState("over");

    adobe livedocs is your friend

    flos

  3. #3
    Member
    Join Date
    Sep 2010
    Posts
    41
    cool, thanks, I'll play with that.
    Still wondering how to make the over state occur for a specified time and then stop.

    I am considering the second option as possibly working better though (because the button mouse over also triggers another event on the stage, so it gets complicated if I trigger the mouseover event with the cue point event), so wondering if you have any advice on this other option: i.e. to use a movie clip (that is the same as the button over state) and add it to the stage in a layer above the existing button. I would have the movie clips in position with visible = false until the cue point is reached at which point I would use:
    movieclip.visible = true;
    movieclip.play();
    and again, how would I tell it to play for 4 seconds and then become invisible again?
    Last edited by myalkut; 10-13-2010 at 10:44 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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center