Copy link to clipboard
Copied
Dear all, Can anyone help me converting this script to AS3, i tried it but it's not worked as I'm no so good.
Stage.align = "TL";
Stage.scaleMode = "noScale";
bc._width = Stage.width; bc._height = Stage.height;
var bc = bc; Stage.addListener(bc); bc.onResize = function() { bc._width = Stage.width; bc._height = Stage.height; };
class balloons_class extends MovieClip {
private var speedMultiplier:Number = 5; private var viewWidth:Number = Stage.width; private var viewHeight:Number = Stage.height; private var speed:Number; private var drift:Number; function balloons_class() { readyBalloon(); moveMe(); } private function readyBalloon():Void { speed = 5 + Math.random() * speedMultiplier; getDrift(); this._y = viewHeight + this._height / 2; this._x = Math.random() * viewWidth; this._xscale = this._yscale = 70 + speed * 10; } private function getDrift():Void { drift = Math.random() * 3; var driftDirection:Number = Math.random() * 10; if (driftDirection < 5) { drift *= -1; } } private function moveMe():Void { this.onEnterFrame = everyFrame; } private function everyFrame():Void { this._y -= speed; this._x += drift; if (this._y < -this._height / 4) { viewWidth = Stage.width; viewHeight = Stage.height; readyBalloon(); } }
}
class confetti_class extends MovieClip {
private var speedMultiplier:Number = 10; private var viewWidth:Number = Stage.width; private var viewHeight:Number = Stage.height; private var speed:Number; private var drift:Number; function confetti_class() { speed = Math.random() * speedMultiplier; readyConf(); moveMe(); } private function readyConf():Void { getDrift(); this._y = -50; this._x = viewWidth - 2 * Math.random() * viewWidth; this._xscale = this._yscale = 70 + speed * 10; } private function getDrift():Void { drift = Math.random() * 3; var driftDirection:Number = Math.random() * 10; if (driftDirection < 5) { drift *= -1; } } private function moveMe():Void { this.onEnterFrame = everyFrame; } private function everyFrame():Void { this._y += speed; this._x += drift; if (this._y > viewHeight+50) { viewWidth = Stage.width; viewHeight = Stage.height; readyConf(); } }
}
I've spent 1-2 on that and still can't figure out how it can work. It will be huge help if anyone can help. Thank you in advance.
Sylvia
Copy link to clipboard
Copied
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
//if bc is to be a MoviClip
var bc:MovieClip = new MovieClip();
//call it once when the app starts
resizeThat();
stage.addEventListener(Event.RESIZE, resizeThat);
function resizeThat(e:Event=null):void{
bc._width = stage.width;
bc._height = stage.height;
}
//Put the following code in a file balloon.as in the same directory as your fla
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class balloon extends MovieClip
{
private var speedMultiplier:Number = 5;
private var viewWidth:Number;
private var viewHeight:Number;
private var speed:Number;
private var drift:Number;
public function balloon()
{
// constructor code
if (stage == null)
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
else
{
init();
}
}
private function init(e:Event = null):void
{
viewWidth = stage.width;
viewHeight = stage.height;
readyBalloon();
this.addEventListener(Event.ENTER_FRAME, everyFrame);
}
private function readyBalloon():void
{
speed = 5 + Math.random() * speedMultiplier;
getDrift();
this.y = viewHeight + this.height / 2;
this.x = Math.random() * viewWidth;
this.scaleX = this.scaleY = 70 + speed * 10;
}
private function getDrift():void
{
drift = Math.random() * 3;
var driftDirection:Number = Math.random() * 10;
if (driftDirection < 5)
{
drift *= -1;
}
}
private function everyFrame(e:Event):void
{
this.y -= speed;
this.x += drift;
if (this.y < this.height / 4)
{
viewWidth = stage.width;
viewHeight = stage.height;
readyBalloon();
}
}
}
}
//Put the following code in a file confetti.as in the same directory as your fla
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class confetti extends MovieClip
{
private var speedMultiplier:Number = 10;
private var viewWidth:Number;
private var viewHeight:Number;
private var speed:Number;
private var drift:Number;
public function confetti()
{
// constructor code
if (stage == null)
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
else
{
init();
}
}
private function init(e:Event = null):void
{
viewWidth = stage.width;
viewHeight = stage.height;
speed = Math.random() * speedMultiplier;
readyConf();
addEventListener(Event.ENTER_FRAME, everyFrame);
}
private function readyConf():void
{
getDrift();
this.y = -50;
this.x = viewWidth - 2 * Math.random() * viewWidth;
this.xscale = this.yscale = 70 + speed * 10;
}
private function getDrift():void
{
drift = Math.random() * 3;
var driftDirection:Number = Math.random() * 10;
if (driftDirection < 5)
{
drift *= -1;
}
}
private function everyFrame(e:Event):void
{
this.y += speed;
this.x += drift;
if (this.y > viewHeight + 50)
{
viewWidth = Stage.width;
viewHeight = Stage.height;
readyConf();
}
}
}
}