views:

135

answers:

4
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*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.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;
}
A: 

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.

Chris Thompson
it may be a good idea in some languages, in an AS2-AS3 translation it is not a very good idea at all.
jonathanasdf
Spent 4 hrs trying that approach but gave even more errors as I am also attaching a component from Max Ms.
Spux
A: 
  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

Omu
+2  A: 

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

Jorge
Oh hello, Brill.
Spux
+3  A: 
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.

jonathanasdf
Thnx so much, have more to work on so will have a go.
Spux