Skip navigation
weston.6
Currently Being Moderated

can anyone help me convert actionscript 2.0 to actionscript 3.0 for my interactive sketchpad?

Nov 4, 2012 8:20 AM

Tags: #air #cs5 #as3 #cs5.5 #3.0 #action_script_3 #actionscript #flash_cs5 #flash_cs5.5 #interactive #animation #actions #conversion #cs6 #2.0 #pad #sketch #flash_cs6 #sketchpad

If anyone can get back to me I'd appreciate the help.

 

I've been working on making an interactive drawing pad but started from a template that was in actionscripts 1&2. but when I converted it to actionscript 3.0  there are errors.

I don't really understand coding very well and was hoping someone could help me make it work for actionscript 3.0.

 

Here is the code for actionscript 2.0 (it works perfectly when in the correct format)

 

lineThickness = 0;

selectedColor = "0x000000";

_root.onMouseDown = startDrawing;

_root.onMouseUp = stopDrawing;

function startDrawing() {

          if (_xmouse<455) {

                    _root.lineStyle(lineThickness, selectedColor);

                    _root.moveTo(_root._xmouse, _root._ymouse);

                    _root.onMouseMove = drawLine;

          }

}

function drawLine() {

          _root.lineTo(this._xmouse, this._ymouse);

}

function stopDrawing() {

          delete this.onMouseMove;

}

line0.onPress = function() {

          lineThickness = 0;

};

line3.onPress = function() {

          lineThickness = 3;

};

line6.onPress = function() {

          lineThickness = 6;

};

colorRed.onPress = function() {

          selectedColor = "0xFF0000";

};

colorGreen.onPress = function() {

          selectedColor = "0x00FF00";

};

colorBlue.onPress = function() {

          selectedColor = "0x0000FF";

};

colorYellow.onPress = function() {

          selectedColor = "0xFFFF00";

};

colorMagenta.onPress = function() {

          selectedColor = "0xFF00FF";

};

colorCyan.onPress = function() {

          selectedColor = "0x00FFFF";

};

colorBlack.onPress = function() {

          selectedColor = "0x000000";

};

eraser_btn.onPress = function() {

_root.clear();

};

 
Replies
  • kglad
    72,166 posts
    Jul 21, 2002
    Currently Being Moderated
    Nov 4, 2012 11:58 AM   in reply to weston.6

     

    var lineThickness:int = 0;

    var selectedColor:int = 0x000000;

    this.addEventListener(MouseEvent.MOUSE_DOWN,startDrawing);

    this.addEventListener(MouseEvent.MOUSE_UP,stopDrawing);

     

    function startDrawing() {

              if (mouseX<455) {

    with(this.graphics){                 

    lineStyle(lineThickness, selectedColor);

                   moveTo(mouseX, mouseY);

                       this.addEventListener(MouseEvent.MOUSE_MOVE, drawLine);

    }

              }

    }

    function drawLine() {

            with(this.graphics){

    lineTo(mouseX, mouseY);

    }

    }

    function stopDrawing() {

              this.removeEventListener(MouseEvent.MOUSE_MOVE,drawLine);

    }

    for(var i:int=0;i<9;i+=3){

    this["line"+i].addEventListener(MouseEvent.MOUSE_DOWN,downF);

    this["line"+i].ivar=i;

    }

    function downF(e:MouseEvent):void{

    lineThickness=MovieClip(e.currentTarget).ivar;

    }

    var colorA:Array=[[colorRed,0xff0000],[colorGreen,0x00ff00], ...,[colorBlack,0x000000]];

    for(i=0;i<colorA.length;i++){

    colorA[i][0].addEventListener(MouseEvent.MOUSE_DOWN,colorF);

    colorA[i][0].ivar=i;

    }

    function colorF(e:MouseEvent):void{

    selectedColor=MovieClip(e.currentTarget).ivar;

    }

    erase_btn.addEventListener(MouseEvent.MOUSE_DOWN,eraseF);
    function eraseF(e:MouseEvent):void{
    this.graphics.clear();
    }
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 8, 2013 8:02 PM   in reply to kglad

    Thank you for the example. I have also tried implementing this, not sure if Weston got what he needed.

    I have: iMac OS X.7.5   2.7GHz i5, 8GB ram - CS6 targeting iOS & Android 3.4 or 3.6 SDK

    I am looking to impliment a simple drawing function. The above looks good and simple to me (not that I understand each process).

    I tried a new AS3 layout, added some buttons represented by the colorGreen etc...

     

    When selecting a colour button, without having drawn, I get an error: ArgumentError: Error #1063: Argument count mismatch on kglad_fla::MainTimeline/startDrawing(). Expected 0, got 1.

    when attempting to draw:

    ArgumentError: Error #1063: Argument count mismatch on kglad_fla::MainTimeline/startDrawing(). Expected 0, got 1.

    ArgumentError: Error #1063: Argument count mismatch on kglad_fla::MainTimeline/stopDrawing(). Expected 0, got 1.

     

    It starts off with this error:

    [SWF] kglad.swf - 83805 bytes after decompression

    TypeError: Error #1010: A term is undefined and has no properties.

              at kglad_fla::MainTimeline/frame1()[kglad_fla.MainTimeline::frame1:31]

              at runtime::ContentPlayer/loadInitialContent()

              at runtime::ContentPlayer/playRawContent()

              at runtime::ContentPlayer/playContent()

              at runtime::AppRunner/run()

              at ADLAppEntry/run()

              at global/runtime::ADLEntry()

     

     

    I tried setting the 'this.' to an 'mc.' instead, and while it alleviated the button error, it got me no further. Could I ask for assistance in getting this functional PLEASE...

    Could you explain to me: colorA[i][0]   (ahhh... found   http://active.tutsplus.com/tutorials/actionscript/as3-101-arrays/ ) another newbie...

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 9, 2013 9:47 AM   in reply to amandasyd

    Change

     

    startDrawing()

     

    to

     

    startDrawing(e:MouseEvent=null)

     

    do the same thing with stopDrawing()

     
    |
    Mark as:
  • kglad
    72,166 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 9, 2013 9:56 AM   in reply to kglad

    use:

     

     

     

     

    var lineThickness:int = 0;

    var selectedColor:int = 0x000000;

    this.addEventListener(MouseEvent.MOUSE_DOWN,startDrawing);

    this.addEventListener(MouseEvent.MOUSE_UP,stopDrawing);

     

    function startDrawing(e:MouseEvent):void {

              if (mouseX<455) {

    with(this.graphics){                 

    lineStyle(lineThickness, selectedColor);

                   moveTo(mouseX, mouseY);

                       this.addEventListener(MouseEvent.MOUSE_MOVE, drawLine);

    }

              }

    }

    function drawLine(e:MouseEvent):void {

            with(this.graphics){

    lineTo(mouseX, mouseY);

    }

    }

    function stopDrawing(e:MouseEvent):void {

              this.removeEventListener(MouseEvent.MOUSE_MOVE,drawLine);

    }

    for(var i:int=0;i<9;i+=3){

    this["line"+i].addEventListener(MouseEvent.MOUSE_DOWN,downF);

    this["line"+i].ivar=i;

    }

    function downF(e:MouseEvent):void{

    lineThickness=MovieClip(e.currentTarget).ivar;

    }

    var colorA:Array=[[colorRed,0xff0000],[colorGreen,0x00ff00], ...,[colorBlack,0x000000]];

    for(i=0;i<colorA.length;i++){

    colorA[i][0].addEventListener(MouseEvent.MOUSE_DOWN,colorF);

    colorA[i][0].ivar=i;

    }

    function colorF(e:MouseEvent):void{

    selectedColor=MovieClip(e.currentTarget).ivar;

    }

    erase_btn.addEventListener(MouseEvent.MOUSE_DOWN,eraseF);
    function eraseF(e:MouseEvent):void{
    this.graphics.clear();
    }
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 9, 2013 4:16 PM   in reply to kglad

    Thank you Amy and Mr K.

     

    Tried that, get an error from line 24

    23. for(var i:int=0;i<9;i+=3){

    24.      this["line"+i].addEventListener(MouseEvent.MOUSE_DOWN,downF);

    25.      this["line"+i].ivar=i;

    26. }

     

    TypeError: Error #1010: A term is undefined and has no properties.

              at kgladD_fla::MainTimeline/frame1()[kgladD_fla.MainTimeline::frame1:24]

              at runtime::ContentPlayer/loadInitialContent()

              at runtime::ContentPlayer/playRawContent()

              at runtime::ContentPlayer/playContent()

              at runtime::AppRunner/run()

              at ADLAppEntry/run()

              at global/runtime::ADLEntry()

     

    Tried changing from iOS SDK 3.6 to to 3.4 and back to Flash11, made little difference except the way the error was handeled..

     

    In trying to follow through, I quoted out the to sections 23-26 and 32-36 (var colorA:Array=[[...)

     

    and notices the effects shown in the diagram

      mrK.jpg

    Strange that the drawing functioned behind or on the button, went point to point between the movieclips... (set with instance names: colorRed, etc) but good to see something (anything) happening - As the mouse is dragged ove the exit button the same drawing pattern (as in/behind the erase button) is seen through the Exit button until the mouse exits that button. If I set the alpha of the colour MC's - you can see the same effect behind them...

    I'm obviously not seeting up the stage elements correctly - have the FLA at http://esdd.us/cs6/kglad.fla

    In anticipation, could the drawing be set on a clear "stage" above a background image or over a background image. Thank you for your time and assistance.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 9, 2013 4:19 PM   in reply to amandasyd

    If I set one MC in the background to cover the full stage - and reduce it's alph to 0 - then the drawing shows up on the whole stage.

     
    |
    Mark as:
  • kglad
    72,166 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 9, 2013 4:31 PM   in reply to amandasyd

    you don't have one or more of line0,...,line8 defined.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 9, 2013 5:59 PM   in reply to kglad

    I probably don't have any defined, but I'll go looking and see what I can learn. Thank you.

     
    |
    Mark as:
  • kglad
    72,166 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 9, 2013 8:11 PM   in reply to amandasyd

    you're welcome.

     

    line0 etc set the thickness of the drawn line.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 9, 2013 9:10 PM   in reply to amandasyd

    var line1:Shape = new Shape();

     

    2, 8, and also did line0...

     

    I wasn't sure if the index would start at 0 or 2 (i+=3) so the last one was suppose to be just incase, should have done a trace before showing how much I don't know.

     

    ReferenceError: Error #1056: Cannot create property ivar on flash.display.Shape.

              at kglad_fla::MainTimeline/frame1()[kglad_fla.MainTimeline::frame1:76]

     

    74. for(var i:int=0;i<9;i+=3){

    75.       this["line"+i].addEventListener(MouseEvent.MOUSE_DOWN,downF);

    76.      this["line"+i].ivar=i;

    77. }

     

    Any further assistance appreciated. Thank you

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 9, 2013 9:34 PM   in reply to amandasyd

    Sorry Mr K, I didn't see the entry at 2:11 - must have already been on this page without refreshing.

     
    |
    Mark as:
  • kglad
    72,166 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 10, 2013 7:12 AM   in reply to amandasyd

    those should be movieclips, not shapes.

     

    they need to be clickable and they should be on-stage.  they are controls that allow the user to control their drawing.

     

    if you don't want to allow that control, you don't need to use that part of the code.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 10, 2013 2:31 PM   in reply to kglad

    Thank you Sir... They were buttons and then back to movieclips when I was looking at the code nd it said:

          lineThickness = MovieClip(e.currentTarget).ivar;

     

    I also found some helpful info on: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc51 6d4fbf351e63e3d118a9b90204-7dd9.html

    It dates back to CS4 but assisted with concept. What I've done for the pallet is put an image of an artist pallet, and select colour from that.

    Thank you (and Amy) for your assistance.

     
    |
    Mark as:
  • kglad
    72,166 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 12, 2013 7:53 AM   in reply to amandasyd

    you're welcome.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points