Search code examples
flashactionscript-3rollover

Rollover point system


2nd: EDIT

This is almost doing it. If the counter reaches 350 and I move my mouse down now it hops on over to 250. I just want it to start counting down. I.e. 349, 348, 347 and so on. What do I need to change?

//Function
function countUp(e:TimerEvent):void{
if (mouseY < 180)
{
myMc.myTxt.text = (String(count+countTimer.currentCount));
}
else{
myMc.myTxt.text = (String(count-countTimer.currentCount));
}
}

EDIT: What do I need to write in AS3 to make a dynamic text field increase in increments of 1 if the user hovers at the upper half of the screen, and decrease in increments of 1 if the user hovers at the lower half of the screen? Purpose, it isn't a game. It's to present an idea for an app.

Original: I need some help, or rather a lot of help, in devising some code that will give a user + points for being at the top half of the screen and minus points for being at the bottom part.

+


-

What I have right now isn't actually doing any of those things, I've just been mucking about trying to get all the masks working and they finally are.

I've included the code to offer as much information as possible about my specific project. There is also a few more lines that changes the colour of the dial when the user rolls over the specific coloured bars. I can post that as well if it helps.

To clarify the scene, the arrow part of the dial tracks the user's mouse. Always pointing towards it. The bars, when rolled over changes the colour of said dial. The "73M" is static, as well is "POINTS" but the 380 value is dynamic. It is that string I need to affect.

If anything is unclear please feel free to ask, I've been at this all night so there is a chance I'm so into it that I can't see straight.

Here's an image if it helps: http://www.dropmocks.com/mBKQEe alt link: https://i.sstatic.net/nJq8g.jpg Don't have any rep to embed this, I'm afraid.

Dynamic text

//Variables
var count:Number = 300;
var countTimer:Timer = new Timer(200,count);
var counter:TextField = myMc.myTxt;

//Event Listener
countTimer.addEventListener(TimerEvent.TIMER, countUp);

//Init
countTimer.start();
counter.text = "300";

//Function
function countUp(e:TimerEvent):void{
myMc.myTxt.text = (String(count+countTimer.currentCount));
}

And the mouse-tracking

// This is for the mouse tracking //
stage.addEventListener("mouseMove",directionFollow);

function directionFollow(e:MouseEvent):void {

var a1 = mouseY - direction1.y;
var b1 = mouseX - direction1.x;
var radians1 = Math.atan2(a1,b1);
var degrees1 = radians1 / (Math.PI / 180);
direction1.rotation = degrees1;
}

Solution

  • Well, right now, you're taking an average starting count (300) and modifying it based on the Timer's count. The problem with this is fairly straightforward. The timer currentCount will go up, and never come down.

    So, say the currentCount is 50. Then count + currentCount is 350, and count - currentCount is 250. Instead of modifying it like this, modify the count variable directly, like this:

    function countUp(e:TimerEvent):void {
        if (mouseY < 180) {
            count++;
        } else {
            count--;
        }
        mcMc.myTxt.text = String(count);
    }
    

    This will simply increment/decrement the count variable based on where the mouse is. In your original example, count never changed. Here, ++ and -- are incrementing or decrementing by one, respectively. They can also be written like this:

    count += 1;
    count -= 1;
    

    or this:

    count = count + 1;
    count = count - 1;
    

    They all mean the same thing, but it's easier to just use ++ and --.