Results 1 to 10 of 10

Thread: ActionScript using rollover to fill a bar

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    5

    ActionScript using rollover to fill a bar

    hi,

    I am using Flash CS4 and actionscript 2.0.

    does anyone know what you would do to make it so that when you mouse over a rectangle, as you move the cursor to the right the bar "fills up" (changes color) as you move it?


    thanks!

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: ActionScript using rollover to fill a bar

    I'm not exactly sure what you mean by "bar", do you mean change the colour of the rectangle?

    Secondly, why are you using actionscript 2.0 in CS4?

    Edit:

    Try this:

    Code:
    this.createEmptyMovieClip("rectangle", 1);
    rectangle._x = 100;
    rectangle._y = 100;
    with (rectangle) {
        lineStyle(1, 0xCCCCCC);
        beginFill(0xEEEEEE);
    	    moveTo(0, 0);
        lineTo(80, 0);
        lineTo(80, 60);
        lineTo(0, 60);
        lineTo(0, 0);
        endFill();
    		    
    };
    rectangle.onRollOver = function() {
    with (rectangle) {
    	beginFill(0x006600);
    		    moveTo(0, 0);
        lineTo(80, 0);
        lineTo(80, 60);
        lineTo(0, 60);
        lineTo(0, 0);
        endFill();
    };
    };
    The above code changes the colour of the rectangle when the mouse moves over it.
    Last edited by Nightwalker83; May 11th, 2009 at 04:53 AM. Reason: Adding more
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    5

    Re: ActionScript using rollover to fill a bar

    by bar I just mean the rectangle object that I am moving the mouse over.

    so yeah, I would like so when I move the cursor over the rectangle to the right, it will look like it's "filling up" by changing color (just in the area you have moved over so far) as you move the mouse further to the right.

    does the code just go in the actions layer? thanks for posting it i will try it out later on when I get back onto my mac

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: ActionScript using rollover to fill a bar

    Quote Originally Posted by nsb2040 View Post
    does the code just go in the actions layer?
    Yes, just place the code in the actions layer, save the project then press "Ctrl" + "Enter"
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    5

    Re: ActionScript using rollover to fill a bar

    well, using that code it fills the whole rectangle with a different color on rollover, but what I had in mind was something like when you move the mouse over the beginning (left side) of the rectangle, the area that changes color is only the part where you have the mouse. Then as you move the mouse over to the right, the color gradually changes and the part to the left of the mouse is the new color and the part to the right of the mouse is still the old color....kind of like a loading bar but you are controlling it with the mouse.

    if you know how this can be done, that'd be sweet - but either way thanks for your help!

  6. #6
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: ActionScript using rollover to fill a bar

    I doubt that is possible because there is no way to tell which part of the rectangle the mouse is over!
    Last edited by Nightwalker83; May 12th, 2009 at 09:21 PM. Reason: Fixing spelling!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    5

    Re: ActionScript using rollover to fill a bar

    Okay, gotcha.

    could you tell me the syntax for changing the color of the rectangle when you roll over it, and then reverting back to the original color when you roll off?

    I know it's just the onRollOver and onRollOff events, but what's the syntax for changing the color?

  8. #8
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: ActionScript using rollover to fill a bar

    To change the colour the first time use the code in post #2. To change the colour on mouse out add:

    Code:
    rectangle.onRollOut = function() {
    with (rectangle) {
    	beginFill(0xEEEEEE);
    		    moveTo(0, 0);
        lineTo(80, 0);
        lineTo(80, 60);
        lineTo(0, 60);
        lineTo(0, 0);
        endFill();
    };
    };
    Edit:

    beginFill tells Flash start the colour fill! EndFill tells Flash to stop the colour fill process.
    Last edited by Nightwalker83; May 12th, 2009 at 11:13 PM. Reason: Adding more
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    5

    Re: ActionScript using rollover to fill a bar

    cool, that works.

    the only issue is, it generates a rectangle that it uses and i already have a rectangle on the stage of a certain size that i want to use. can i make it so it just references the rectangle i already have on the stage?

  10. #10
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: ActionScript using rollover to fill a bar

    Quote Originally Posted by nsb2040 View Post
    cool, that works.

    the only issue is, it generates a rectangle that it uses and i already have a rectangle on the stage of a certain size that i want to use. can i make it so it just references the rectangle i already have on the stage?
    I have already tried it and it doesn't work because the normal shape creation doesn't use the "instance name" tag. The instance name refers to an object.

    If you want to change the height or width of the rectangle created by te above code change the numbers in the brackets, example:

    Code:
       lineTo(800, 0);
        lineTo(800, 600);
        lineTo(0, 600);
        lineTo(0, 0);
    Edit:

    Please append the original post thread title to include "Resolved" if you quest have been answered.
    Last edited by Nightwalker83; May 13th, 2009 at 03:14 AM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

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