forked from: ff[2]: Mouse Position Gradation
画像:きまぐれアフターさま
http://www5d.biglobe.ne.jp/~gakai/
音声:効果音ラボさま
http://soundeffect-lab.info/
/**
* Copyright H.S ( http://wonderfl.net/user/H.S )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/KPZa
*/
// forked from makc3d's ff[2]: Mouse Position Gradation
// forked from H.S's forked from: Mouse Position Gradation
// forked from kawamura's Mouse Position Gradation
package {
import flash.display.GradientType;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;
import flash.display.Loader;
import flash.media.*;
import flash.net.URLRequest;
import flash.system.LoaderContext;
public class FlashTest extends Sprite {
private var sprite:Sprite;
private var loaderArray:Array = [];
private var soundArray:Array = [];
public function FlashTest() {
// write as3 code here..
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private var day:SoundChannel, stDay:SoundTransform = new SoundTransform(0, 0);
private var evening:SoundChannel, stEvening:SoundTransform = new SoundTransform(0, 0);
private var night:SoundChannel, stNight:SoundTransform = new SoundTransform(0, 0);
private var midnight:SoundChannel, stMidnight:SoundTransform = new SoundTransform(0, 0);
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
day = (new Sound(new URLRequest("http://chococornet.sakura.ne.jp/sound/sound_1.mp3"))).play (0, int.MAX_VALUE, stDay);
evening = (new Sound(new URLRequest("http://chococornet.sakura.ne.jp/sound/sound_2.mp3"))).play (0, int.MAX_VALUE, stEvening);
night = (new Sound(new URLRequest("http://chococornet.sakura.ne.jp/sound/sound_3.mp3"))).play (0, int.MAX_VALUE, stNight);
midnight = (new Sound(new URLRequest("http://chococornet.sakura.ne.jp/sound/mute.mp3"))).play (0, int.MAX_VALUE, stMidnight);
for (var i:int = 0; i < 4; i++) {
loaderArray.push(new Loader());
}
soundArray.push(stDay, stEvening, stNight, stMidnight);
loaderArray[0].load(new URLRequest("http://chococornet.sakura.ne.jp/img/background_day_2.png"), new LoaderContext(true));
loaderArray[0].name = "day";
loaderArray[1].load(new URLRequest("http://chococornet.sakura.ne.jp/img/background_evening.png"), new LoaderContext(true));
loaderArray[1].name = "evening";
loaderArray[2].load(new URLRequest("http://chococornet.sakura.ne.jp/img/background_night_2.png"), new LoaderContext(true));
loaderArray[2].name = "night";
loaderArray[3].load(new URLRequest("http://chococornet.sakura.ne.jp/img/background_midnight.png"), new LoaderContext(true));
loaderArray[3].name = "midnight";
stage.addChildAt(loaderArray[0], 0);
addChild(loaderArray[1]);
sprite = new Sprite();
addChild(sprite);
blendMode = "layer";
sprite.blendMode = "alpha";
var g:Graphics;
g = sprite.graphics;
var type:String = GradientType.LINEAR;
var colors:Array = [0x0, 0x0];
var alphas:Array = [1.0, 0.0];
var ratios:Array = [0.0, 0xFF];
var matrix:Matrix = new Matrix();
matrix.createGradientBox(20, 100, 0.0 * Math.PI, 80, 0);
g.beginGradientFill(type, colors, alphas, ratios, matrix);
g.drawRect(0, 0, 100, 100);
sprite.width = stage.stageWidth;
sprite.height = stage.stageHeight;
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
private function enterFrameHandler(e:Event):void
{
var rate:Number = stage.mouseX / stage.stageWidth;
if (rate > 0.95) rate = 1;
if (rate < 0.05) rate = 0;
var name:String = stage.getChildAt(0).name
soundArray[0].volume = (name=="day" || name=="night")? 1 - rate : rate; day.soundTransform = stDay;
soundArray[1].volume = 1 - soundArray[0].volume; evening.soundTransform = stEvening;
soundArray[2].volume = 0; night.soundTransform = stNight;
soundArray[3].volume = 0; midnight.soundTransform = stMidnight;
var g:Graphics;
g = sprite.graphics;
g.clear();
var type:String = GradientType.LINEAR;
var colors:Array = [0x0, 0x0];
var alphas:Array = [1.0, 0.0];
var ratios:Array = [0.0, 0xFF];
var matrix:Matrix = new Matrix();
matrix.createGradientBox(30, 100, 0.0 * Math.PI, -30 + 130 * rate, 0);
g.beginGradientFill(type, colors, alphas, ratios, matrix);
g.drawRect(0, 0, 100, 100);
if ((rate > 0.95 && (name == "day" || name == "night")) || (rate < 0.05 && (name == "evening" || name == "midnight")) ) {
loaderArray.push(loaderArray.shift());
soundArray.push(soundArray.shift());
stage.removeChildAt(0);
removeChildAt(0);
stage.addChildAt(loaderArray[0], 0);
addChildAt(loaderArray[1], 0);
sprite.blendMode = (sprite.blendMode == "alpha")? "erase" : "alpha";
}
}
}
}