A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: using a timerHandler value somewhere else in the code

  1. #1
    Member
    Join Date
    Mar 2007
    Posts
    66

    using a timerHandler value somewhere else in the code

    Hi,
    in this code, how do I have to program the function timerHandler or what do I have to do so that it's value (which is now traced) can be used elsewhere in the code? (I need it for the rotation of the arm (mc_arm.rotation))
    Any idea?
    Thanks in advance.


    Code:
    import mathfiles.com.flashcreations.utils.MathExtra;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.events.Event;
    import flash.net.URLRequest;
    
    
    var trk1:Sound = new Sound();
    var trkChannel1:SoundChannel = new SoundChannel();
    var req:URLRequest = new URLRequest("Sound/aleatoric inspiration_2.mp3");
    trk1.load(req);
    var myTimer:Timer = new Timer(100);
    
    
    stage.addEventListener(MouseEvent.MOUSE_DOWN, pressHandler);
    //trkChannel1.addEventListener(Event.ENTER_FRAME, onEnterFrame);
    myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
    
    function pressHandler(e:Event):void {
    	stage.addEventListener(MouseEvent.MOUSE_MOVE, moveHandler);
    	stage.addEventListener(MouseEvent.MOUSE_UP, upHandler);
    	trkChannel1.stop();
    	myTimer.stop();
    	if (mc_arm.rotation > 10) {
    	mc_vinyl.gotoAndPlay(2);
    	}
    	if (mc_arm.rotation < 10) {
    	mc_vinyl.gotoAndPlay(1);
    	}
    }
    function moveHandler(e:Event):void {
    	if (mc_area.hitTestPoint(mouseX,mouseY,true)) {
    		mc_arm.rotation=(((MathExtra.rotation2(mouseX-mc_arm.x,mouseY-mc_arm.y))-21.5)/15.5)*45;
    	}
    //	trace(moveArm);
    
    }
    function upHandler(e:Event):void {
    	stage.removeEventListener(MouseEvent.MOUSE_UP, upHandler);
    	stage.removeEventListener(MouseEvent.MOUSE_MOVE, moveHandler);
    	var starts:Number=(1-(15+((mc_arm.rotation/45)*30))/45)*trk1.length;
    	trkChannel1 = trk1.play(starts);
    	myTimer.start();
    	if (mc_arm.rotation > 10) {
    	mc_vinyl.gotoAndPlay(2);
    	}
    }
    
    
    function timerHandler (e:TimerEvent) {
    	trace(trkChannel1.position);
    	}

  2. #2
    Member
    Join Date
    Aug 2010
    Posts
    65
    simply store it in a variable.
    myvar = trkChannel1.position;

  3. #3
    Member
    Join Date
    Mar 2007
    Posts
    66
    i thought about this, too, but i need the output of the function timerHandler
    (a constantly updated trkChannel.position, while the sound is playing).
    Can I store this function in a variable?

  4. #4
    Member
    Join Date
    Mar 2007
    Posts
    66
    i tried this:

    Code:
    var pos:Number
    
    function timerHandler (e:TimerEvent):void {
    	pos = Number(trkChannel1.position);
    	}
    
    trace(pos);

    but then i get the feedback "NaN". Of what type is trkChannel1.position?
    And why can I not cast it to a number?

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The position property is a Number, but in the code above you are tracing before the function has had a chance to evaluate and set pos.

    What are you trying to do with pos?

  6. #6
    Member
    Join Date
    Mar 2007
    Posts
    66
    I need pos for the mc_arm.rotation equation (see complete code on top). I want to map somehow trkChannel1.position to mc_arm.rotation, but a constantly updated (every 100 ms) trkChannel1.position,
    therefore the timer functionality.

  7. #7
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    So just set mc_arm.rotation in timerHandler.

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