-
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);
}
-
simply store it in a variable.
myvar = trkChannel1.position;
-
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?
-
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?
-
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?
-
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.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|