The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 8 of 8

Thread: actionscript 3.0 click event listeners

  1. #1
    12
    posts
    Registered User

    actionscript 3.0 click event listeners

    Hi people.
    I am stuck. Any help would be most appreciated.

    I need to change the following opensourced ActionScript3.0:

    import gs.*;
    TweenMax.to(this, 0.5, {alpha: 0.4});
    this.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
    this.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
    this.addEventListener(MouseEvent.CLICK, click);

    function click(event:MouseEvent):void
    {
    var
    URL:URLRequest = new URLRequest(http://www.iss-web.co.uk);
    navigateToURL(URL);
    }

    function mouseOverHandler(e:Event):void {
    TweenMax.to(this, 0.5, {alpha: 1});
    }

    function mouseOutHandler(e:Event):void {
    TweenMax.to(this, 0.5, {alpha: 0.4});
    }


    Specifically I need to change the click event listener to 'gotoAndPlay' from the timeline in my flash file, rather than have it as a link to a URL.

    I have tried several ways around this and had my actionscript in place without any compile errors; however the click event did not function as instructed.
    Does anyone have a quick solution to this?

    Many thanks in anticipation,

    Aaron

  2. #2
    easy.
    this.addEventListener(MouseEvent.CLICK, click);
    function click(event:MouseEvent):void
    {
    gotoAndPlay(2); //put frame name or number here

    }

    above is for if you are refering to the entire stage. If you want to have it go to a timeline of a movieclip, say the one you clicked on,
    just type
    event.target.gotoAndPlay(2);

    hope that helps.

  3. #3
    12
    posts
    Registered User
    Quote Originally Posted by myoreo View Post
    easy.
    this.addEventListener(MouseEvent.CLICK, click);
    function click(event:MouseEvent):void
    {
    gotoAndPlay(2); //put frame name or number here
    }

    above is for if you are refering to the entire stage. If you want to have it go to a timeline of a movieclip, say the one you clicked on,
    just type
    event.target.gotoAndPlay(2);

    hope that helps.
    Thanks for reply -
    I do need it to goto a frame in a movie clip

    but i am unsure what to write in place of event.target ??

    the movie clip has an instance of 'content'


    "event.target.gotoAndPlay(2);"
    works as good code - but the specified function of going to a particular frame within a particular movie clip does not happen. As I understand it the code as it is doesnt give any indication of which movie clip to go to in order to play from the particular frame.
    Last edited by asest; August 18th, 2009 at 08:20 AM. Reason: new understanding

  4. #4
    Hey dude

    This any good?

    If each movieclip has an addEventListener(MouseEvent.CLICK, click) event then that reference is passed to click as event.target. Not sure what this default type is (Object?).

    Anyways i think you need to cast it to say event.target is a Movieclip and then play that casting.

    PHP Code:
    function click (event:MouseEvent): void
    {
              var 
    movieClip:MovieClip MovieClip(event.target);
              
    movieClip.gotoAndPlay(2);

    or

    PHP Code:
    function click(event:MouseEvent): void
    {
            
    MovieClip(event.target).gotoAndPlay(2);

    Last edited by grandpaw broon; August 18th, 2009 at 09:18 AM.
    jings

  5. #5
    Write all code on the main timeline; do not nest code within a movieclip.
    And do not send requests from child objects directly to parent objects.
    (if you want to do it this way, use custom classes (OOP) instead of writing the code within the FLA)
    Code:
    // this code is on frame1 of the main timeline
    // on the stage you have the button and the MovieClip "content"
    
    buttonInstanceNameHere.addEventListener(MouseEvent.CLICK, click);
    
    function click(event:MouseEvent): void
    {
            content.gotoAndPlay(2);
    }
    I used to be a paranoid-psychotic-schizophrenic, but don't worry, he's dead now.

  6. #6
    12
    posts
    Registered User
    okay, nothing there seemed to work (though there may have been conflicting code being pulled in and/or it may have been problems with my scope)

    I'm trying from scratch to do what I want...

    Have a movie clip (set of images) scroll across the page on mouseover.
    I have this working.
    However; it resets and starts again everytime the mouseover is reactivated.
    I have thought I could solve this using an 'if'statement.

    E.g....
    {
    if (
    //images position x value == 0
    )
    images.gotoAndPlay("");
    }

    I am unsure how to declare the condition so that the images MC only gets activated by mouseover in the event that its x position is 0.

    I could even use the condition that if the frame number is '2' then goto and play

  7. #7
    12
    posts
    Registered User
    sorted.

    function
    mouseEventHandler1 (evt:MouseEvent):void
    {
    if (images.currentFrame == 1)
    {
    images.gotoAndPlay("2");
    }
    else if (images.currentFrame == 239)
    {
    images.gotoAndPlay("2");
    }
    else (images.currentFrame!= 1 || images.currentFrame != 239)
    {
    }
    }

    Now I want to make each image within the tweening movieclip a 'mousedown' operator to gotoandplay another MC.

    ...............

  8. #8
    Quote Originally Posted by myoreo View Post
    easy.
    this.addEventListener(MouseEvent.CLICK, click);
    function click(event:MouseEvent):void
    {
    gotoAndPlay(2); //put frame name or number here

    }

    above is for if you are refering to the entire stage. If you want to have it go to a timeline of a movieclip, say the one you clicked on,
    just type
    event.target.gotoAndPlay(2);

    hope that helps.
    I think so it is better to use event.currentTarget.gotoAndPlay(2);

    Because if it clicked on movieclip and that movieclip has textfield on top than the target will be textfield so you cannot say textfield.gotoAndPlay(2). currentTarget will give you the movieclip instance.
    ------------------------------------------------------------------------
    If my help was uselful to you.
    “Plenty of people despise money, but few know how to give it away.” - Francois de La Rochefoucauld
    Asif Maknojia.
    http://www.flopsoft.co.nr

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012