homepage Welcome to WebmasterWorld Guest from 54.226.93.128
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
Forum Library, Charter, Moderator: open

Flash and Shockwave Forum

    
Creating flash 'whiteboard'
i have a script but need to modify it
HelenDev




msg:1565215
 12:14 pm on Jun 3, 2004 (gmt 0)

I want to create a flash movie that has a board you can draw on. I found this script on the net somewhere which creates a simple drawing pad which is great.

However I need to make this so that the drawing board is only part of the movie, rather than the whole movie, as it is presently. ie I want the drawing pad to sit inside some other graphics.

Here is the code:

init();
stop();
//
function init() {
initDrawing();
initMouse();
}

function initDrawing() {
createEmptyMovieClip("draw_mc", 10);
draw_mc.lineStyle(2, 0x000000);
createEmptyMovieClip("temp_mc", 20);
}

function initMouse() {
mouseMoveListener = new Object();
mouseMoveListener.onMouseMove = function() {
mouseMoveEvent();
};
//
mouseClickListener = new Object();
mouseClickListener.onMouseDown = function() {
mouseDownEvent();
};
mouseClickListener.onMouseUp = function() {
mouseUpEvent();
};
Mouse.addListener(mouseClickListener);
}

function mouseDownEvent() {
draw_mc.moveTo(_xmouse, _ymouse);
Mouse.addListener(mouseMoveListener);
}

function mouseUpEvent() {
temp_mc.clear();
Mouse.removeListener(mouseMoveListener);
}

function mouseMoveEvent() {
// Remove any previous drawing
temp_mc.clear();
// Draw dot at End Point
temp_mc.lineStyle(6, 0x00ff00);
temp_mc.moveTo(_xmouse, _ymouse);
temp_mc.lineTo(_xmouse + 0.5, _ymouse);
// Draw line segment
draw_mc.lineTo(_xmouse, _ymouse);
}

// this actionscript goes in frame 1

I am able to use flash on a quite basic level and am happy to play with the actionscript, even if I'm not always sure what I'm doing!

Any help would be much appreciated.

 

benihana




msg:1565216
 12:43 pm on Jun 3, 2004 (gmt 0)

try publishing that from flash to create a self contained .swf containing the whiteboard, then in the parent movie with the other graphics use loadMovie [macromedia.com] to load the whiteboard in.

ben

<added> alternatively, you could create a new moiveclip (insert > symbol) and add that script to the first frame of the new movieclips timeline.

you can then drag that new movieclip from the library onto the stage with the rest of your graphics etc

HelenDev




msg:1565217
 3:01 pm on Jun 3, 2004 (gmt 0)

Cheers for the reply ben.

When I create the movieclip and drop this in, it works, but I don't know how to get the movieclip (drawing pad) to be the exact size I want. At the moment the user can draw all over the surroundings.

it is possible that it's past dumb o'clock for me

benihana




msg:1565218
 3:14 pm on Jun 3, 2004 (gmt 0)

hmm . didnt think of that.

you could possibly add an if statement to check the mouses position before drawing, something alongm the lines of:

function mouseDownEvent() {
if (_xmouse>=100&&_xmouse=<400&&_ymouse>=100&&_ymouse=<400)
{
draw_mc.moveTo(_xmouse, _ymouse);
Mouse.addListener(mouseMoveListener);
}
}

so basically you can only draw if the mouse is between 100 and 400 px along both the x axis and y axis - experiment with co-ordinates to suit.

note: totally untested code. sounds ok in theory but...

HelenDev




msg:1565219
 3:34 pm on Jun 3, 2004 (gmt 0)

Cheers again ben. You look like a bit of a flash pro to me. I shall come to you with all my flash problems ;)

It just occured to me to put the 'surroundings' in the layer above the movieclip and voila, it works. Told you it was past dumb o'clock :)

benihana




msg:1565220
 3:37 pm on Jun 3, 2004 (gmt 0)

yep thats probably a much better idea .

flash problems

he he - i tend to goto to winstun when hes about :)

good luck

winstun




msg:1565221
 3:44 pm on Jun 3, 2004 (gmt 0)

Also if you're putting the drawing pad mc into a container ( blank mc to 'hold' the pad ) then you could put:
function mouseDownEvent() {
var clip = this._parent;
if (_xmouse>=clip._x&&_xmouse=<(clip._x+clip._width)&&_ymouse>=clip._y&&_ymouse=<(clip._y+clip._height)){
draw_mc.moveTo(_xmouse, _ymouse);
Mouse.addListener(mouseMoveListener);
}
}

This way it's more dynamic and re-usable so you can use it in other applications and with the option of resizing it.
Long story short is so you don't have go in and edit the function every time you need a different size.

winstun




msg:1565222
 3:47 pm on Jun 3, 2004 (gmt 0)

Thanks for the props, Ben, but just doing my part to help out. :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved