dcsimg
A Flash Developer Resource Site

Results 1 to 12 of 12
  1. #1
    Junior Member
    Join Date
    Aug 2016
    Posts
    8

    [LITTLE HELP] Create an "up-down" variable

    Hello everybody!
    I need a variable to go up from 1 to 100, once at 100 go down back to 1, and so on, up and down.
    What is the best and easiest way to do it?

    Thanks a lot!

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,769
    The simplest would probably just to set the variable manually. A nice way to do that with one statement would be like this:
    Code:
    i=(i==1)?100:1;
    http://help.adobe.com/en_US/FlashPla...ml#conditional
    .

  3. #3
    Junior Member
    Join Date
    Aug 2016
    Posts
    8
    Hi Swak, that only returns 1, 100, 1, 100, 1 ...and so on.
    Not the numbers between.
    I might be not clear indeed.
    I need a variable that returns "1,2,3,4,5,6,7,8,9...37..68...99,100 AND GO DOWN 99,98,97,96....6,5,4,3,2,1 AND GO UP AGAIN
    Thanks anyways

  4. #4
    Senior Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    920
    wow i=(i==1)?100:1; looks really cool how can you call a function with that? I have tried countless times to use that question mark
    My 3D browser based flash demo, you can draw on the wall and it saves forever: https://spark.adobe.com/page/oXRKzNxeb9p1t/

  5. #5
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,769
    tonaz79
    I see, there's a simple way of doing that then.
    Code:
    var i:int = 1;
    var c:int = 1;
    function count ():void {
    	i +=  c;
    	switch (i) {
    		case 100 :
    			c = -1;
    			break;
    		case 1 :
    			c = 1;
    			break;
    	}
    }
    This is the basic idea. I just used an enterFrame function to continuously call the count() function.



    Alloy Bacon
    The ? is not a function really. It's more like they took an if statement and turned it into an operator like the +-*/ symbols. Bascially you have 3 parts for it to work.
    s1?s2:s3
    s1 needs to be a bool. If s1 is true then it returns s2. Otherwise it returns s3.
    Here's an example: i=false?1:2;
    with that i will be equal to 2. If it's true then i will equal 1.
    I like it, it makes for a simple operator when you understand it. In fact you can use it for a if else shorthand.
    Here's an example: false?trace("1"):trace("2");
    That will always trace 2.
    .

  6. #6
    Senior Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    920
    Thats almost like .bat syntax
    My 3D browser based flash demo, you can draw on the wall and it saves forever: https://spark.adobe.com/page/oXRKzNxeb9p1t/

  7. #7
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,769
    If everything's good please add a "[RESOLVED][LITTLE HELP] Create an "up-down" variable" tag. Thanks!
    .

  8. #8
    Member
    Join Date
    Oct 2016
    Posts
    54
    lol no like bat. echo

  9. #9
    Senior Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    920
    lol who ever uses that syntax to type must look like this or something because thats not normal:
    My 3D browser based flash demo, you can draw on the wall and it saves forever: https://spark.adobe.com/page/oXRKzNxeb9p1t/

  10. #10
    Member
    Join Date
    Oct 2016
    Posts
    54
    now you be silly allooy.
    you say it look like .bat code, i say it not look like .bat code, you just want answer things when not right.

    http://www.instructables.com/id/5-Cool-Batch-Files/

  11. #11
    Member
    Join Date
    Oct 2016
    Posts
    54
    now you be silly allooy.
    you say it look like .bat code, i say it not look like .bat code, you just want answer things when not right.

    http://www.instructables.com/id/5-Cool-Batch-Files/

    good self pic you have, allieoony baccoony

  12. #12
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    893
    ��
    who is this? a word of friendly advice: FFS stop using AS2

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

×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.