A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Need help: Round to a number from a range of numbers

  1. #1
    Member
    Join Date
    Nov 2007
    Posts
    83

    Need help: Round to a number from a range of numbers

    Hello. This may be a stupid question but I hope I can get help with the structure of my code at least. I'm trying to syncronize an audio and some text by highlighting it.

    In the main movie I have counter variable which calls charCounter3.as and timeVars variable which calls timeSettings.as I have onEnterFrame function that highlights the text while sound is playing. My code is:

    Code:
    function onEnterFrame(e:Event):void {
    	pos=soundChannel.position;
    	var minutes:uint=Math.floor(soundChannel.position/1000/60);
    	var seconds:uint=Math.floor(soundChannel.position/1000)%60;
    	debug_txt.text='position: '+pos;
    
    	if (pos>=timeVars.setTimes(globalNum)) {
    		if (pos<timeVars.setTimes(globalNum+1)) {
    
    			txt.setTextFormat(def_tf, 0, txt.length);
    			txt.setTextFormat(hl_tf, counter.breakPos[globalNum], counter.breakPos[globalNum+1]);
    			globalNum=(timeVars.timeArr as Array).indexOf(Math.floor(pos));
    		}
    	}
    }
    Highlighted text needs to be updated on audio forwards and backwards. I think onEnterFrame isn't being able to catch the timeArr values. I will be glad if someone helps.

  2. #2
    Senior Member
    Join Date
    Jan 2010
    Posts
    141
    can't help with code, but do know how to round numbers:

    Math.round() this will round numbers

    Math.floor() this will always round down

    Math.ceil() this will always round up


    Hope that helps : )

  3. #3
    Member
    Join Date
    Nov 2007
    Posts
    83
    word2yerMom thanks for your reply. I have to find out how to detect if position is in range of numbers (variables).

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