A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 27

Thread: Problems with coding rollover

  1. #1
    Senior Member
    Join Date
    Oct 2005
    Posts
    157

    Arrow Problems with coding rollover

    Hello everyone, I am making a website with three buttons on the main page, and they are movieclips with instance names box1, box2, and box3. I had my actions in the movieclips themselves, but I want to move the rollover actions to the main timeline (since I want more than one button to move after box1 is rolled over).
    Anyways, the main problem is I do not know how I can target a specific movieclip.

    This is my code in my main timeline:
    Code:
    box1.addEventListener(MouseEvent.ROLL_OVER, manageMouseOver, false, 0, true);
    box1.addEventListener(MouseEvent.ROLL_OUT, manageMouseOut, false, 0, true);
     
    function manageMouseOver(event:MouseEvent):void{
    gotoAndPlay("Over");
    }
     
    function manageMouseOut(event:MouseEvent):void{
    gotoAndPlay("Out");
    }
    My old code (worked perfect except I don't know how to make other buttons move as well as "this.") that I put in each movieclip was:
    Code:
    this.addEventListener(MouseEvent.ROLL_OVER, gotoOver);
    
    function gotoOver(event:MouseEvent):void
    {
    gotoAndPlay("Over");
    }
    
    this.addEventListener(MouseEvent.ROLL_OUT, gotoOut);
    
    function gotoOut(event:MouseEvent):void
    {
    gotoAndPlay("Out");
    }

    Thank you in advance,
    SK

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    May be this is what you want? Change
    gotoAndPlay("Over");
    to
    event.currentTarget.gotoAndPlay("Over");
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173
    Actionscript Code:
    remotebase_mc.addEventListener(MouseEvent.ROLL_OVER, buttonRollOver);
    remotebase_mc.addEventListener(MouseEvent.ROLL_OUT, buttonRollOut);

    function buttonRollOver(event:Event):void {
        remotebase_mc.alpha=1;
        remspeed=-8;
        if (starthere_mc.alpha ==1){
            starthere_mc.alpha = 0;
        }
    }

    function buttonRollOut(event:Event):void {
        remotebase_mc.alpha=.5;
        remspeed=8;
    }

    thats some of my script, and it functions perfect...

    so Im not sure what you are doing wrong...


    are your movieclips embedded into another clip of some kind?

    OTHERCLIPNAME.remotebase_mc.addEventListener(Mouse Event.ROLL_OUT, buttonRollOut);

    if that is the case...

  4. #4
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173
    ohh im dumb... duh...

    function manageMouseOver(event:MouseEvent):void{
    box1.gotoAndPlay("Over");
    }

    function manageMouseOut(event:MouseEvent):void{
    box1.gotoAndPlay("Out");
    }

  5. #5
    Senior Member
    Join Date
    Oct 2005
    Posts
    157
    I just updated my script to:

    Code:
    import  flash.display.MovieClip;
    import  flash.events.MouseEvent;
    
    box1.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandler);
    box1.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandler);
    box1.addEventListener(MouseEvent.CLICK, onClickHandler);
    
    function onRollOverHandler(myEvent:MouseEvent){
    box1.gotoAndPlay("Over");
    }
    
    function onRollOutHandler(myEvent:MouseEvent){
    box1.gotoAndPlay("Out");
    }
    
    function onClickHandler(myEvent:MouseEvent){
    box1.gotoAndPlay("Click");
    box2.gotoAndPlay("Click");
    box3.gotoAndPlay("Click");
    }
    
    box2.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandler2);
    box2.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandler2);
    
    function onRollOverHandler2(myEvent:MouseEvent){
    box2.gotoAndPlay("Over");
    }
    
    function onRollOutHandler2(myEvent:MouseEvent){
    box2.gotoAndPlay("Out");
    }
    
    box3.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandler3);
    box3.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandler3);
    
    function onRollOverHandler3(myEvent:MouseEvent){
    box3.gotoAndPlay("Over");
    }
    
    function onRollOutHandler3(myEvent:MouseEvent){
    box3.gotoAndPlay("Out");
    }
    The problem now is, for some reason, when I roll over box1, the other boxes just look like the "over" frames. They do not play the motion tween that I put to animate. I also tested not using a motion tween but the same thing happens

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    That is why I said before you should use
    event.currentTarget.gotoAndPlay("Over");
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Senior Member
    Join Date
    Oct 2005
    Posts
    157
    Oh I thought I did have that, can you please show me how my script would look with that incorporated in it? That would be a great help

  8. #8
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173
    thats what hes saying, i just put it in laymen terms for you...

    currentTarget = box1,box2,box3 ect...

    im not sure what the prior event in front of the currentTarget is for or representing though...

    The problem now is, for some reason, when I roll over box1, the other boxes just look like the "over" frames. They do not play the motion tween that I put to animate. I also tested not using a motion tween but the same thing happens
    im confused... can you post you FLA? im sure I can point you in the right direction if Im looking at what your looking at!

  9. #9
    Senior Member
    Join Date
    Oct 2005
    Posts
    157
    here's my .fla, copyrighted
    please let me know what you can do
    Attached Files Attached Files

  10. #10
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173
    you love me long time...


    Actionscript Code:
    import flash.display.*;
    import flash.events.*;

    //box1
    box1.addEventListener(MouseEvent.ROLL_OVER, box1rollin);
    box1.addEventListener(MouseEvent.ROLL_OUT, box1rollout);

    //box2
    box2.addEventListener(MouseEvent.ROLL_OVER, box2rollin);
    box2.addEventListener(MouseEvent.ROLL_OUT, box2rollout);


    //box3
    box3.addEventListener(MouseEvent.ROLL_OVER, box3rollin);
    box3.addEventListener(MouseEvent.ROLL_OUT, box3rollout);


    //boxclicks
    box1.addEventListener(MouseEvent.CLICK, box1click);
    box2.addEventListener(MouseEvent.CLICK, box2click);
    box3.addEventListener(MouseEvent.CLICK, box3click);

    //functions roll in and outs

    function box1rollin(myEvent:MouseEvent) {
        box1.gotoAndStop("Over");
    }
    function box1rollout(myEvent:MouseEvent) {
        box1.gotoAndStop("Out");
    }

    function box2rollin(myEvent:MouseEvent) {
        box1.gotoAndStop("Over");
    }
    function box2rollout(myEvent:MouseEvent) {
        box1.gotoAndStop("Out");
    }

    function box3rollin(myEvent:MouseEvent) {
        box1.gotoAndStop("Over");
    }
    function box3rollout(myEvent:MouseEvent) {
        box1.gotoAndStop("Out");
    }

    //fucntions for clicks

    function box1click(event:MouseEvent) {
        box1.removeEventListener(MouseEvent.ROLL_OVER, box1rollin);
        box1.removeEventListener(MouseEvent.ROLL_OUT, box1rollout);
        box1.gotoAndPlay("click");

    }
    function box2click(event:MouseEvent) {
        box2.removeEventListener(MouseEvent.ROLL_OVER, box2rollin);
        box2.removeEventListener(MouseEvent.ROLL_OUT, box2rollout);
        box2.gotoAndPlay("click");

    }
    function box3click(event:MouseEvent) {
        box3.removeEventListener(MouseEvent.ROLL_OVER, box3rollin);
        box3.removeEventListener(MouseEvent.ROLL_OUT, box3rollout);
        box3.gotoAndPlay("click");

    }


    we woulda never worked that out by your description...

    keep in mind that actionscript is case sensitive a value of: "Click" is different then "click" (im pretty sure)
    Last edited by YBAB; 03-31-2011 at 06:41 PM.

  11. #11
    Senior Member
    Join Date
    Oct 2005
    Posts
    157
    Thank you guys so much for the fantastic help! I'm almost done with my scripting, but I got stuck on this.. I wanted it so that after one of the buttons were clicked (and the buttons all slide down) that a different part would be played on each button movie clip (a part where they don't slide down again). The reason I don't want them to all slide down again is because after the first click, a content box is placed above the buttons after they slide down. Please let me know if this doesn't make sense, or i'm just talking confusing.

    This is my script so far:
    Code:
    import flash.display.*;
    import flash.events.*;
    
    //box1
    box1.addEventListener(MouseEvent.ROLL_OVER, box1rollin);
    box1.addEventListener(MouseEvent.ROLL_OUT, box1rollout);
    
    //box2
    box2.addEventListener(MouseEvent.ROLL_OVER, box2rollin);
    box2.addEventListener(MouseEvent.ROLL_OUT, box2rollout);
    
    
    //box3
    box3.addEventListener(MouseEvent.ROLL_OVER, box3rollin);
    box3.addEventListener(MouseEvent.ROLL_OUT, box3rollout);
    
    
    //boxclicks
    box1.addEventListener(MouseEvent.CLICK, box1click);
    box2.addEventListener(MouseEvent.CLICK, box2click);
    box3.addEventListener(MouseEvent.CLICK, box3click);
    
    //functions roll in and outs
    
    function box1rollin(myEvent:MouseEvent) {
        box1.gotoAndPlay("Over");
    }
    
    function box1rollout(myEvent:MouseEvent) {
        box1.gotoAndPlay("Out");
    }
    
    function box2rollin(myEvent:MouseEvent) {
        box2.gotoAndPlay("Over");
    }
    function box2rollout(myEvent:MouseEvent) {
        box2.gotoAndPlay("Out");
    }
    
    function box3rollin(myEvent:MouseEvent) {
        box3.gotoAndPlay("Over");
    }
    function box3rollout(myEvent:MouseEvent) {
        box3.gotoAndPlay("Out");
    }
    
    //fucntions for clicks
    
    function box1click(event:MouseEvent) {
        box1.removeEventListener(MouseEvent.ROLL_OVER, box1rollin);
        box1.removeEventListener(MouseEvent.ROLL_OUT, box1rollout);
    	box2.removeEventListener(MouseEvent.ROLL_OVER, box2rollin);
    	box2.removeEventListener(MouseEvent.ROLL_OUT, box2rollout);
    	box3.removeEventListener(MouseEvent.ROLL_OVER, box3rollin);
    	box3.removeEventListener(MouseEvent.ROLL_OUT, box3rollout);
        box1.gotoAndPlay("click");
    	box2.gotoAndPlay("click");
    	box3.gotoAndPlay("click");
    	gotoAndPlay("transition");
    
    }
    function box2click(event:MouseEvent) {
        box2.removeEventListener(MouseEvent.ROLL_OVER, box2rollin);
        box2.removeEventListener(MouseEvent.ROLL_OUT, box2rollout);
    	box1.removeEventListener(MouseEvent.ROLL_OVER, box1rollin);
        box1.removeEventListener(MouseEvent.ROLL_OUT, box1rollout);
    	box3.removeEventListener(MouseEvent.ROLL_OVER, box3rollin);
    	box3.removeEventListener(MouseEvent.ROLL_OUT, box3rollout);
    	box2.gotoAndPlay("click");
    	box1.gotoAndPlay("click");
    	box3.gotoAndPlay("click");
    	gotoAndPlay("transition2");
    
    }
    function box3click(event:MouseEvent) {
        box1.removeEventListener(MouseEvent.ROLL_OVER, box1rollin);
    	box1.removeEventListener(MouseEvent.ROLL_OUT, box1rollout);
    	box2.removeEventListener(MouseEvent.ROLL_OVER, box2rollin);
    	box2.removeEventListener(MouseEvent.ROLL_OUT, box2rollout);
    	box3.removeEventListener(MouseEvent.ROLL_OVER, box3rollin);
        box3.removeEventListener(MouseEvent.ROLL_OUT, box3rollout);
        box3.gotoAndPlay("click");
    	box1.gotoAndPlay("click");
    	box2.gotoAndPlay("click");
    	gotoAndPlay("transition3");
    
    }

  12. #12
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173
    glad I could help ^_^.. let me know if anything else comes up

    (good job on keeping your script a little better in structure this time)

  13. #13
    Senior Member
    Join Date
    Oct 2005
    Posts
    157
    "I wanted it so that after one of the buttons were clicked (and the buttons all slide down) that a different part would be played on each button movie clip (a part where they don't slide down again). The reason I don't want them to all slide down again is because after the first click, a content box is placed above the buttons after they slide down."


  14. #14
    Senior Member
    Join Date
    Oct 2005
    Posts
    157

    Question Preloading

    Hey guys, thanks for all the help, my website looks great! One thing, I was trying to set up a preloader, but the problem is that it doesn't really preload everything. When i test it in any browser, its very slow at the beginning (the preloading goes fast but doesnt seem to work).
    It looks like my background movieclip needs to be loaded separately or something, im not sure. That's what is making it slow though.

    Sadly, i cannot upload the file since its too big (even zipped) so I will show you my script for the preloader:

    Code:
    import flash.display.*;
    this.stop();
    this.loaderInfo.addEventListener (ProgressEvent.PROGRESS, PL_LOADING);
    function PL_LOADING(event:ProgressEvent):void {
    var pcent:Number=event.bytesLoaded/event.bytesTotal*100;
    bar_mc.scaleX=pcent/100;
    textBox.text=int(pcent)+"%";
    if(pcent==100){
    this.gotoAndPlay(2);
    }
    }
    Please take a look and let me know!

    Thanks again

  15. #15
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173
    url?

  16. #16
    Senior Member
    Join Date
    Oct 2005
    Posts
    157
    its not on the web yet could I email it?
    Imagination is the creator of reality...

  17. #17
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173
    as soon as you upload it, swing me a message ill take a look, and try to help you out!

  18. #18
    Senior Member
    Join Date
    Oct 2005
    Posts
    157
    it wont let me upload because it says I already used up the data storage. How can I get rid of the old ones?

  19. #19
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173
    log onto your ftp and delete them

  20. #20
    Senior Member
    Join Date
    Oct 2005
    Posts
    157
    oh on flashkit i meant
    sry im quite a noob haha
    Imagination is the creator of reality...

Tags for this Thread

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