School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 309,235 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,765 people online right now. Registration is fast and FREE... Join Now!




multiPle user drawing board in flash as3.0

 

multiPle user drawing board in flash as3.0, How would I go about sending and retrieveing said ByteArray data fro

bindumisra

19 Jun, 2009 - 03:56 AM
Post #1

New D.I.C Head
*

Joined: 19 Jun, 2009
Posts: 2

CODE
var canvas:Sprite = new Image();
canvas.x = 10;
canvas.y = 10;
this.stage.addChild(canvas);
//
var myBitmapData:BitmapData = new BitmapData (canvas.width, canvas.height, false, 0x00FFFFFF);
var bytes:ByteArray;
//
var child:Shape = new Shape();
var isDrawing:Boolean = false;
canvas.stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
canvas.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
canvas.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
function mouseDownHandler(event:MouseEvent) {
    isDrawing = true;
    if ( isDrawing) {
        child.graphics.lineStyle(2, 0xFF0000);
        child.graphics.moveTo(mouseX, mouseY);
    }
}
function mouseMoveHandler(event:MouseEvent) {
    if (isDrawing) {
        child.graphics.lineTo(mouseX, mouseY);
    }
    if (mouseX < canvas.stage.getBounds(this).x || mouseX >295) {
        isDrawing = false;
    }
    if (mouseY < canvas.stage.getBounds(this).y || mouseY >145) {
        isDrawing = false;
    }
}
function mouseUpHandler(event:MouseEvent) {
    canvas.addChild(child);
    isDrawing = false;
    var rect:Rectangle = new Rectangle(0, 0, canvas.width, canvas.height);
    myBitmapData.draw(canvas);
    
    

    bytes = myBitmapData.getPixels(rect);
    //
    bytes.position = 0;
}





function TimerExample() {
    var myTimer:Timer = new Timer(5000, 1);
    
    myTimer.addEventListener(TimerEvent.TIMER, drawRectangle);
    //myTimer1.addEventListener(TimerEvent.TIMER, drawRectangle1);
    myTimer.start();
    
}



TimerExample();

function drawRectangle(evt:TimerEvent):void {
    if (this.getChildByName("bm") != null) {
        this.removeChild(this.getChildByName("bm"));
    }
    
     var url:String = "http://localhost:81/Drawing/save.php";
    
     var request:URLRequest = new URLRequest(url);
     var loader:URLLoader = new URLLoader (request);
       request.data = bytes;
     request.method = URLRequestMethod.POST;                
     request.contentType = 'application/octet-stream';
        loader.addEventListener(Event.COMPLETE, onComplete);
    loader.load(request);
    
        
}
function onComplete (event:Event):void{
    
        statusTxt1.text = event.target.data;
        trace(event.target.data);

        var myBitmapData_2:BitmapData = new BitmapData (canvas.width, canvas.height, false, 0x00FFFFFF);
        var rect_2:Rectangle = new Rectangle(0, 0, canvas.width, canvas.height);
        myBitmapData_2.setPixels(rect_2, event.target.data);
        var bm:Bitmap = new Bitmap(myBitmapData_2);
        bm.name = "bm";
        this.addChild(bm);
        bm.x = 200;
        bm.y = 200;
}


User is offlineProfile CardPM
+Quote Post

 
Reply to this topicStart new topic
Replies(1 - 2)

BetaWar

RE: MultiPle User Drawing Board In Flash As3.0

19 Jun, 2009 - 07:36 AM
Post #2

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 4,780



Thanked: 277 times
Dream Kudos: 1400
My Contributions
Well, I can't really read much of your problem (is all in the topic description), but I believe you are asking about how to transfer the data. That requires having a socket server somewhere out there which all the people using the drawing board are connected to. Then you get the byte array information and send that to the server, which in turn sends it to everyone else.

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

User is offlineProfile CardPM
+Quote Post

bindumisra

RE: MultiPle User Drawing Board In Flash As3.0

19 Jun, 2009 - 08:47 PM
Post #3

New D.I.C Head
*

Joined: 19 Jun, 2009
Posts: 2

How would I go about sending and retrieveing said ByteArray data from the server using php and having Flash rebuild the BitmapData that was stored as a ByteArray? i m not able to rebuild .


Attached File(s)
Attached File  Drawing.zip ( 12.72k ) Number of downloads: 66
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/26/09 08:57AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month