Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Results 1 to 2 of 2

Thread: Drawing API

  1. #1
    Junior Member Settled In PBKHouston is on a distinguished road
    Join Date
    May 2008
    Posts
    1
    Rep Power
    0

    Drawing API

    amazing Flash templates
    I have added a little to some code that another user had written for drawing a square, but I have some question. As of now when the user clicks and drags on the stage you draw a square. I have it so you can change the color and stroke color of the square. Here is what I want to do. Instead of the user clicking and dragging on the stage I want them to first click a button that represents the object to be drawn and then that activates the code to draw the rectangle as the click and drag on the stage. Here is the code:

    [as]
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    import flash.display.Stage;
    import fl.controls.ColorPicker;
    import fl.events.ColorPickerEvent;

    var mouseIniX:Number;
    var mouseIniY:Number;

    var chosenColour:uint = 0;
    var chosenColour2:uint = 0;

    // This will hold a reference to the current created object
    // on the onMouseDownEvent and is going to be used to create shape
    var mcRef:MovieClip;

    fCP.addEventListener(ColorPickerEvent.CHANGE, changeHandler);
    sCP.addEventListener(ColorPickerEvent.CHANGE, changeHandler2);

    stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
    stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);

    function changeHandler(event:*):void {
    chosenColour = event.currentTarget.selectedColor;
    }

    function changeHandler2(event:*):void {
    chosenColour2 = event.currentTarget.selectedColor;
    }

    // Functions to handle object dragging
    function startDraging(e:MouseEvent):void
    {
    e.target.startDrag();
    }

    function stopDraging(e:MouseEvent):void
    {
    e.target.stopDrag();
    }


    function onMouseDownHandler(e:MouseEvent) {
    if ( e.target is Stage )
    {
    mouseIniX = mouseX;
    mouseIniY = mouseY;

    // Create our new square and add some listeners to it to enabled dragging
    var mc:MovieClip = new MovieClip();
    mc.buttonMode = true;
    mc.addEventListener(MouseEvent.MOUSE_DOWN, startDraging);
    mc.addEventListener(MouseEvent.MOUSE_UP, stopDraging);
    addChild( mc );
    // Hold a reference so we can update its graphics using the drawing API
    mcRef = mc;

    // DRAW!
    stage.addEventListener(Event.ENTER_FRAME, square);
    }
    }

    function onMouseUpHandler(e:MouseEvent) {
    stage.removeEventListener(Event.ENTER_FRAME, square);
    }

    function square(e:Event):void
    {
    mcRef.graphics.clear();
    mcRef.graphics.lineStyle(1, chosenColour2, 1.0);
    mcRef.graphics.beginFill(chosenColour, 1.0);
    mcRef.graphics.drawRect(mouseIniX, mouseIniY, mouseX - mouseIniX, mouseY - mouseIniY);
    mcRef.graphics.endFill();
    }

    [/as]

    I am just frustrated because I have tried changing the code up and can not seem to figure it out. Please, can someone help me. Here is a link to how it works as well. The square button as of now does not work, which is what I am trying to figure out.

    http://www.pbk.com/draw/fromMario3.html

  2. #2
    Junior Member Settled In gauravS is on a distinguished road
    Join Date
    Aug 2008
    Posts
    1
    Rep Power
    0

    Re: Drawing API

    i ve one question can we make these drawn rectangle button at run time and give it urls too ??/
    If u know then please let me know

    Thanks

+ Reply to Thread

Similar Threads

  1. Drawing polygons with Actionscript 3.0
    By Flep in forum Tutorials
    Replies: 2
    Last Post: 23-07-09, 10:50
  2. Drawing with actionscript 3.0
    By Flep in forum Tutorials
    Replies: 0
    Last Post: 03-10-07, 19:34
  3. Drawing with Actionscript 3.0 - script 2
    By Flep in forum Tutorials
    Replies: 0
    Last Post: 27-09-07, 21:00
  4. Drawing with Actionscript 3.0 - script 3
    By Flep in forum Tutorials
    Replies: 0
    Last Post: 27-09-07, 09:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Optimization by vBSEO