开发者

This codes in Actionscript-2, Can anyone help me translate it into AS-3 please ?.......a newby pulling her hair out !

开发者 https://www.devze.com 2022-12-27 10:42 出处:网络
this.createEmptyMovieClip(\'mask_mc\',0); bg_mc.setMask(mask_mc); var contor:Number=0; // function drawCircle draws a circle on mask_mc MovieClip of radius r and having center to mouse coordinates
this.createEmptyMovieClip('mask_mc',0); 
bg_mc.setMask(mask_mc);
var contor:Number=0;

// function drawCircle draws a circle on mask_mc MovieClip of radius r and having center to mouse coordinates
function drawCircle(mask_mc:MovieClip):Void{
    var r:Number = 20;
    var xcenter:Number = _xmouse;
    var ycenter:Number = _ymouse;
    var A:Number = Math.tan(22.5 * Math.PI/180);
    var endx:Number;
    var endy:Number;
    var cx:Number;
    var cy:Number;

    mask_mc.beginFill(0x000000, 100);
    mask_mc.moveTo(xcenter+r, ycenter);
    for (var angle:Number = Math.PI/4; angle<=2*Math.PI; angle += Math.PI/4) {
       xend = r*Math.cos(angle);
       yend = r*开发者_如何学CMath.sin(angle);

       xbegin =xend + r* A *Math.cos((angle-Math.PI/2));
       ybegin =yend + r* A *Math.sin((angle-Math.PI/2));
       mask_mc.curveTo(xbegin+xcenter, ybegin+ycenter, xend+xcenter, yend+ycenter);
    }
    mask_mc.endFill();
}

// contor variable is used to hold if the mouse is pressed (contor is 1) or not (contor is 0)
this.onMouseDown=function(){
    drawCircle(mask_mc);
    contor=1;
}

// if the mouse is hold and moved then we draw a circle on the mask_mc
this.onMouseMove=this.onEnterFrame=function(){
    if (contor==1){
        drawCircle(mask_mc);
    }
}
this.onMouseUp=function(){
    contor=0;
}


var mask_mc:MovieClip = new MovieClip();
bg_mc.setMask(mask_mc);
var contor:Number=0;

// function drawCircle draws a circle on mask_mc MovieClip of radius r and having center to mouse coordinates
function drawCircle(mask_mc:MovieClip):void{
    var r:Number = 20;
    var xcenter:Number = mouseX;
    var ycenter:Number = mouseY;
    var A:Number = Math.tan(22.5 * Math.PI/180);
    var endx:Number;
    var endy:Number;
    var cx:Number;
    var cy:Number;

    mask_mc.graphics.beginFill(0x000000, 100);
    mask_mc.graphics.moveTo(xcenter+r, ycenter);
    for (var angle:Number = Math.PI/4; angle<=2*Math.PI; angle += Math.PI/4) {
       xend = r*Math.cos(angle);
       yend = r*Math.sin(angle);

       xbegin =xend + r* A *Math.cos((angle-Math.PI/2));
       ybegin =yend + r* A *Math.sin((angle-Math.PI/2));
       mask_mc.graphics.curveTo(xbegin+xcenter, ybegin+ycenter, xend+xcenter, yend+ycenter);
    }
    mask_mc.graphics.endFill();
}

// contor variable is used to hold if the mouse is pressed (contor is 1) or not (contor is 0)
addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
addEventListener(MouseEvent.MOUSE_MOVE, mouseMoved);
addEventListener(MouseEvent.MOUSE_UP, mouseUp);
function mouseDown(e:MouseEvent):void{
    drawCircle(mask_mc);
    contor=1;
}
function mouseMoved(e:MouseEvent):void{
    if (contor==1){
        drawCircle(mask_mc);
    }
}
function mouseUp(e:MouseEvent):void{
 contor=0;
}

see how simple it was to translate? You should try to translate it yourself first and post your attempt.

This is just a direct translation of your snippet. You will have to remove the event listeners or there will be a memory leak.


These links might be useful for you:
AS2 to AS3 Migration Cheatsheet
ActionScript Migration Cookbook


Well sometimes the best way to get started with something like is just try to compile it as AS-3 and see where it blows up. Some of the code will work and then you can type the errors into google (or if you get stuck post specific questions to SO). That will be a lot easier than just trying to "translate" it if you don't know AS very well and understand the differences.


  1. put it in flex builder

  2. try to compile

  3. if you get some errors, fix them

if you don't know how to fix them, google or ask the pleps

0

精彩评论

暂无评论...
验证码 换一张
取 消