A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: problem with mmm...

  1. #1
    Member
    Join Date
    Jul 2003
    Location
    Earth
    Posts
    74

    problem with mmm...

    Hi,

    in a part of a flash application I use two buttons to increase or decrease a particular number to which a limit is set. I added some correction options to that, like when you select that number and enter a "NaN", after pressing a button it should be corrected to "1", or if you enter a higher number than the limit, it should be decreased to the limit.

    But the problem is: when the limit is set to a number higher that 9 (say 20), and you enter a number lower than 9, it acts as if it were a "higher than the limit" number. The other problem is when I enter a big number and press one of the buttons, sometimes it really increases/decreases the number once, although it is far higher than the limit. Only when I press the button once again, it changes the number to the limit!!


    Here is the code to the ">" button:
    Code:
    on (release) {
    	if (isNan(_root.mynumber)) {
    		_root.mynumber = 1;
    	} else if (_root.mynumber>_root.lastnumber) {
    		_root.mynumber = _root.lastnumber;
    	} else {
    		if (_root.mynumber<_root.lastnumber) {
    			_root.mynumber++;
    		}
    	}
    }

    and for the "<" one:
    Code:
      on (release) {
    	if (isNan(_root.mynumber)) {
    		_root.mynumber = 1;
    	} else if (_root.mynumber>_root.lastnumber) {
    		_root.mynumber = _root.lastnumber;
    	} else {
    		if (_root.mynumber>1) {
    			_root.mynumber--;
    		}
    	}
    }

    The fla is attached too.


    Thank you very much for your attention and help

    nominee
    Attached Files Attached Files

  2. #2
    Member
    Join Date
    Jul 2003
    Location
    Earth
    Posts
    74
    Hi again,

    I found out that the error occurs only when I enter a single-digit number which is greater than the leftmost figure of the limit number. e.g.: the limit (_root.lastnumber) is set to 462, and 5 is entered (between the buttons: _root.mynumber). In this case seems flash to assume 5 greater than 462, because "5" is bigger than "4"... !


    Please help!!!
    thanks
    Last edited by nominee; 08-28-2004 at 07:50 PM.

  3. #3
    Senior Member hum's Avatar
    Join Date
    Sep 2003
    Location
    CloudCuckooland
    Posts
    1,714
    Hi.....
    Here you go.....this should do it.......
    I was going to add the ....isNaN...function to the limit number
    (_root.lastnumber).... as well, in case a letter is accidentally typed but i thought you might not need that....anyway..hope this helps

  4. #4
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    put this in frame 1
    Code:
    stop();
    _root.mynumber = 0;
    _root.lastnumber = 0;
    onEnterFrame = function () {
    if (_root.mynumber>_root.lastnumber) {
    _root.mynumber = _root.lastnumber;
    }
    }
    //all the other stuff you have on the mc actions
    and change the vars on the text fields to mynumber and lastnumber rather than _root.mynumber and _root.lastnumber

    then take all the code off the mcs except for the onpress functions (or you can even just make them buttons)

    if you're still having problems reply back and i'll post the fla i tested on (which works 100%)

  5. #5
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    doh! you werent' there when i started typing, hum! sorry bout that

  6. #6
    Senior Member hum's Avatar
    Join Date
    Sep 2003
    Location
    CloudCuckooland
    Posts
    1,714
    hehe......interesting to see how other FK members approached this one

  7. #7
    Member
    Join Date
    Jul 2003
    Location
    Earth
    Posts
    74
    Dear hum, dear moagrius,

    thank you very very much for your kind help, now it works!

    but I'm still curious why does flash do so..., as it makes the same error with moagrius' solution; I set the limit number to 54, and as soon as I type "8" in "mynumber", it goes to 54!

    However, once again a flasher's (nominee's) life was saved!!!

    Cool cheers!
    nominee

  8. #8
    Member
    Join Date
    Jul 2003
    Location
    Earth
    Posts
    74
    Oh no, sorry, it's not over

    I've just noticed that I have the same code on another button

    if (_root.mynumber>_root.lastnumber) {
    _root.mynumber= _root.lastnumber;
    }


    ( This is so simple, why shouldn't it work properly?!!


  9. #9
    Member
    Join Date
    Jul 2003
    Location
    Earth
    Posts
    74
    hey,

    I have an idea:

    Code:
      
    on (press) {
    	_root.mynumber++;
    	_root.mynumber--;
    	if (_root.mynumber>_root.lastnumber) {
    		_root.mynumber = _root.lastnumber;
    	} else if (isNan(_root.mynumber)) {
    		_root.mynumber = 1;
    	}
    }

    That works!!! funny, isn't it?
    seems that it needs just any other code before the comparison, to warm up the flash calculation engine

  10. #10
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    here's an all script version with a couple extra features; just stick it in frame 1, then save/close the fla.

    Code:
    _root.lnv = "0";
    _root.mnv = "0";
    this.createTextField("mntf", 3, 200, 0, 55, 15);
    with (this.mntf) {
    	type = "input";
    	border = true;
    	variable = "mnv";
    }
    this.createTextField("lntf", 4, 100, 0, 55, 15);
    with (this.lntf) {
    	type = "input";
    	border = true;
    	variable = "lnv";
    }
    this.createEmptyMovieClip("b1", 1);
    with (this.b1) {
    	lineStyle(0, 0x666666);
    	beginFill(0xff9933);
    	lineTo(0, 15);
    	lineTo(55, 15);
    	lineTo(55, 0);
    	lineTo(0, 0);
    	endFill();
    }
    duplicateMovieClip("b1", "b2", 2);
    this.b2._x = 300;
    this.b1.onPress = function() {
    	if (_root.mnv>0) {
    		_root.mnv--;
    	}
    	calc();
    };
    this.b2.onPress = function() {
    	_root.mnv++;
    	calc();
    };
    function calc() {
    	_root.lnv = parseInt(_root.lnv);
    	_root.mnv = parseInt(_root.mnv);
    	if (_root.mnv>_root.lnv) {
    		_root.mnv = _root.lnv;
    	}
    	}
    onEnterFrame = function () {
    	if (_root.lnv<=0 || isNan(_root.lnv)) {
    		_root.lnv = 0;
    	}
    	if (_root.mnv<=0 || isNan(_root.mnv)) {
    		_root.mnv = 0;
    	}
    	for (var l = 96; l<=106; l++) {
    		if ((Key.isDown(Key.ENTER)) || (Key.isDown(Key.TAB)) || (Key.isDown(l)) || (Key.isDown(l-48))) {
    			calc();
    		}
    	}
    };

  11. #11
    Member
    Join Date
    Jul 2003
    Location
    Earth
    Posts
    74
    WOW!!! that's a great script!! thanks a lot moagrius

    Although I do not understand the whole calculating thing at a glance, but I will try to take some parts to my application.

    By the way, if you'd like to see it:

    www.gehoerbildung.com/gs/gsintd.htm
    www.gehoerbildung.com/gs/gsakk.htm
    www.gehoerbildung.com/gs/gsintr.htm


    (3 "ear training" programs for musicians)
    (load an exercise from the tab bar (select exercise nr. and press "Übung laden"), and after you have heared it, you can enter the notes, and let the program tell you which are correct/false [except gs-intr]) (the "check" button is the one right to "play")
    Last edited by nominee; 08-29-2004 at 01:08 PM.

  12. #12
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    that's a really cool site nominee, seriously.

    p.s. if you end up using any of that script let me know so i can tell ppl i helped

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