AS2 code to AS3
So i have a problem. I found a cool old tv grain code (here :http://www.republicofcode.com/tutori...ash/old_grain/), but its written in AS2, and i want to convert it to AS3. So heres the original script
onClipEvent (enterFrame) {
_x = random(640);
_y = random(480);
_rotation = random(360);
_alpha = random(100);
_xscale = nue;
_yscale = nue;
nue = random(65);
}
My re-wrote version:
addEventListener(Event.ENTER_FRAME,start);
function start (e:Event):void{
x = Math. random()*640;
y = Math.random()*480;
rotation = Math.random()*360;
alpha = Math.random()*100;
scaleX = nue;
scaleY = nue;
nue = Math.random()*65;
But it says : 1120: Access of undefined property nue. Do you have any idea how to fix it?
Thanks in advance!
Hey guys! Thank you for your help! I'm "working" with flash for 2 days so you both s开发者_JS百科aved my life. I tried to solve my problem, and read about it but since my first language is not English it was a bit complicated! So thanks again, A girl from Hungary BTW. this is the final code
var nue:Number= 65;
addEventListener(Event.ENTER_FRAME, update);
function update(event:Event):void {
x = Math. random()*640;
y = Math.random()*480;
rotation = Math.random()*360;
alpha = Math.random()*10;
nue = Math.random()*65;
scaleX = nue;
scaleY = nue;
}
Yes, you have to declare nue
as a variable:
var nue:Number=1;
addEventListener(Event.ENTER_FRAME, update);
function update(event:Event):void {
x = Math. random()*640; // I think 640 must be stage.stageWidth
y = Math.random()*480; // and 480 must be stage.stageHeight
rotation = Math.random()*360;
alpha = Math.random(); // In AS2 alpha goes from 0 to 100 in AS3 goes from 0 to 1
scaleX = nue;
scaleY = nue;
nue = Math.random()*65;
}
In AS3 you cannot have a variable with no value and expect it to have one. You should give it a value or set it as undefined.
You use nue
at the end of your function, then you give it a value, it needs to be the other way around:
var nue:Number;
addEventListener(Event.ENTER_FRAME, update);
function update(event:Event):void {
x = Math. random()*640;
y = Math.random()*480;
rotation = Math.random()*360;
alpha = Math.random();
nue = Math.random()*65; // set nue
scaleX = nue; // then use it
scaleY = nue;
}
Also note that the alpha
property in AS3 has a range of 0 to 1 inclusive, not 0 to 100.
精彩评论