Saturday, 22 May 2010

More Specific Conditionals for Entering Sleep

The previous actionScript example would trigger an event if the mouse was not moved for a variable amount of time. This was a good start for the project but I wanted to improve the specific values that would start this process. I couldn't start this segment of code until I had first created the XML music app but now that is finalized I have created an 'if' condition for a more complex event.


function onMouseTimer(e:TimerEvent):void{

if (currentIndex ==3 && musicOn>0){

trace("You have fallen asleep");

}
}



'current Index' refers to the song number in the XML list. In this case 'currentIndex==3' refers to track 4 as index starts on zero. 'musicOn' is a binary on or off value that determines whether or not the song is paused. This stops any action from being triggered if the user happens to stop moving the mouse whilst paused on track 4. I have also included volume control that makes the music louder depending on how close to the music source the user point of view is.


This extra conditional code seemed especially necessary, as through testing I determined a user would always trigger the sleep event accidentally when flicking through the songs on the music player as it did not require much mouse movement. The next step of this process is to select and create fitting tracks for the theme of the project.

No comments:

Post a Comment