A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: createEmptyMovieClip question

  1. #1
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356

    createEmptyMovieClip question

    when you create an empty movie clip, is there a way to specify the size you want? i'm learning to use the lineTo method and i'm making a painting "application" to test what i've learned. I'd like to make a virtual sheet of paper on top of my main movie, which will contain buttons to change the color of the line being drawn.
    The code i am using to create the "paper" is this:
    Code:
    _root.createEmptyMovieClip("paper", 100);
    finally, here's my question- is there a way i can define the dimensions of this movie clip i created? I'd like to confine the drawing space to an area that doesnt overlap the buttons that choose color, or the "Clean Page" button.

    thanks,
    -myk

  2. #2
    Senior Member
    Join Date
    Sep 2001
    Location
    Manhattan
    Posts
    398
    Ofcourse there is a way to resize the new movieclip. When you first created it you gave it an instance name called "paper".

    _root.paper._width=10000000;

    will set the width to an astronomical #.

    _root.paper._height=2;

    will set the height to 2.

    Here is what I am missing though... Are you attaching anything to that clip? I ask this because as it stands it is empty and therefore invisible and dimensionless until you fill it with something. Regardless of my question though the code I gave you above should do the trick.
    JA

  3. #3
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356
    hi, thanks for the response.
    The empty movie clip acts as the paper that the drawing takes place on.
    After creating the movieCLip, i have the following:

    Code:
    paper.lineStyle(4, 0x000000, 100);
    paper.onMouseMove = function() {
    	if (drawing == true) {
    		paper.lineTo(_xmouse, _ymouse);
    	}
    }
    paper.onMouseDown = function() {
    	paper.moveTo(_xmouse, _ymouse);
    	drawing = true;
    }
    paper.onMouseUp = function() {
    	drawing = false;
    	paper.lineStyle(4, 0x000000, 100);
    }
    i just want to size my paper so i can have my interface around it without drawing over it.
    Now, if i resize my paper and want to place it in a specific spot, when i set the x and y properties, is that referencing the top left corner of the MC?

    thanks,
    -myk

  4. #4
    Senior Member
    Join Date
    Sep 2001
    Location
    Manhattan
    Posts
    398
    Now, if i resize my paper and want to place it in a specific spot, when i set the x and y properties, is that referencing the top left corner of the MC?
    That is correct.
    JA

  5. #5
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356
    me again,
    when i set the width and height, nothing shows up when i try to draw.
    I i set the x,y properties, i am still able to draw, but the line that's drawn if offset, its a good bit down and to the right of the actual mouse position..

    here's my most recent attempt. The width/height has been commented out so that the line will show up..

    Code:
    _root.createEmptyMovieClip("paper", 100);
    //_root.paper._x = 90;
    //_root.paper._y = 57;
    _root.paper._width = 398;
    _root.paper._width - 283;
    paper.lineStyle(4, 0xFFFFFF, 100);
    paper.onMouseMove = function() {
    	if (drawing == true) {
    		paper.lineTo(_xmouse, _ymouse);
    	}
    }
    paper.onMouseDown = function() {
    	paper.moveTo(_xmouse, _ymouse);
    	drawing = true;
    }
    paper.onMouseUp = function() {
    	drawing = false;
    	paper.lineStyle(4, 0xFFFFFF, 100);
    }
    thanks,
    -myk

  6. #6
    Senior Member
    Join Date
    Sep 2001
    Location
    Manhattan
    Posts
    398
    I have a question for you... Will the movieclip called "paper" always be the same size? Meaning when you are trying to set the height and width will you always be setting it to the same height and width no matter what?
    JA

  7. #7
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356
    yes. once i get it set, i want it it stay that way. i guess the best wa to picture it is this..
    the stage is a square, and "paper" will be a smaller square within the stage that will act as the drawing surface. Once the cursor moves outside of "paper" i dont want any drawing outside of its boundaries.

    thanks,
    -myk

  8. #8
    Senior Member
    Join Date
    Sep 2001
    Location
    Manhattan
    Posts
    398
    My suggestion is to attach a moviclip to the inside of the empty clip to give it dimension. Make a movieclip with a white square inside of it. Make the square the correct size that you want the drawing surface to be. In the library export the movieclip to actionscript. Give it an id name(for example I will use "page")
    Then you will need to attach the movieclip with the white square to the movieclip called "paper" like so:

    paper.attachMovie("page","pageNewInstanceName","") ;

    What this does is it takes what is in your library and puts it into the paper movieclip. If you have specific questions feel free to ask and I will clarify. Good luck
    JA

  9. #9
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356
    J,
    - i appreciate you fooling with this for me..
    i understand the theory behind what you are telling me,but apparently, i am butchering the script.

    here's what i got:

    Code:
    _root.createEmptyMovieClip("paper", 100);
    paper.attachMovie("chalkBoard","newChalkBoard");
    paper.lineStyle(4, 0xFFFFFF, 100);
    paper.onMouseMove = function() {
    	if (drawing == true) {
    		paper.lineTo(_xmouse, _ymouse);
    	}
    }
    paper.onMouseDown = function() {
    	paper.moveTo(_xmouse, _ymouse);
    	drawing = true;
    }
    paper.onMouseUp = function() {
    	drawing = false;
    	paper.lineStyle(4, 0xFFFFFF, 100);
    }
    when i try it, the movie clip i'm trying to attach doesnt show up, and the drawing fuction doesnt operate either. I'm gonna try specifying a depth to the attachMovie while i wait, but any input would be great.. I'm gonna get this down if it kills me!

    -myk


  10. #10
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356

    update

    okay, when i specified depth, the movieClip showed up, and the reason my writing would show was that i had the line color set to white (oops).

    New issue:
    the writing shows up under the movie clip, and is not bound by its dimensions.

    -myk

  11. #11
    Huygens to Titan PCRIDE's Avatar
    Join Date
    May 2002
    Location
    PLUTO
    Posts
    1,335
    r
    All out of Honey Buffers, so i grabed a few Goose Heads

  12. #12
    Senior Member
    Join Date
    Sep 2001
    Location
    Manhattan
    Posts
    398
    The reason why it is showing up under what you attached is because you attached it to a level above what you are drawing. It is late now but tomorrow I will take a look at the code myself and see what I can come up with.
    JA

  13. #13
    Senior Member
    Join Date
    May 2001
    Location
    Toronto
    Posts
    128
    Hi mykrob,

    It's been a while I know but I'm wondering if you ever figured out your drawing boundary problem? If you have, I'd love to see it. I too had a similar issue but I've been able to solve it by setting a boundary within the function that traces the drawing within the empty mc. I'd be happy to share the code with you if you'd like.

    Novian

  14. #14
    Junior Member
    Join Date
    Jun 2003
    Posts
    6
    hi i am trying to figure outthe same problem as dicussed here. would you share your code i'd love to see a solution

  15. #15
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    1) you cant size an empty clip. Setting the _height or _width of an empty clip is useless because theres nothing to size. Whats with width of nothing? nothing. Whats the width of nothing stretched out to 200 px? Well, since its nothing, still nothing!

    2) for restricting drawing you would have to restrict the values that go into your lineTo methods so they do not surpas whatever imaginary boundry youve set up for yourself. Even if you use a non-empty clip like a square to represent your drawing area, lineTo and the other drawing methods aren't restricted to the current size of the clip; they can easily go outside those bounds. Then too, would you need to restrict the values that go into the drawing methods used.

    Basic restriction code is

    Math.min(Math.max( LOWVALUE, changingValue), HIGHVALUE);

    Where LOWVALUE and HIGHVALUE are your limits for both high and low values and changingValue is the value that you are restricting, like _xmouse or _ymouse.

    With that, some plug-and-play code would be

    code:
    _root.createEmptyMovieClip("paper", 1);
    paper.lineStyle(0, 0, 100);
    XMIN = 50;
    XMAX = 250;
    YMIN = 50;
    YMAX = 250;
    paper.onMouseDown = function() {
    var x = Math.min(Math.max(XMIN, this._xmouse), XMAX);
    var y = Math.min(Math.max(YMIN, this._ymouse), YMAX);
    this.moveTo(x,y);
    this.onMouseMove = function() {
    x = Math.min(Math.max(XMIN, this._xmouse), XMAX);
    y = Math.min(Math.max(YMIN, this._ymouse), YMAX);
    this.lineTo(x, y);
    }
    };
    paper.onMouseUp = function() {
    delete this.onMouseMove;
    };



    Now, this will restrict the drawing to those edges as if you are trying to move your pen off but its not going off, its just sitting there on the edge. Alternatively, you can just cut off the drawing when it goes off the edge:

    code:
    _root.createEmptyMovieClip("paper", 1);
    paper.lineStyle(0, 0, 100);
    XMIN = 50;
    XMAX = 250;
    YMIN = 50;
    YMAX = 250;
    paper.onMouseMove = function() {
    var x = Math.min(Math.max(XMIN, this._xmouse), XMAX);
    var y = Math.min(Math.max(YMIN, this._ymouse), YMAX);
    if (Key.isDown(1) && x == this._xmouse && y == this._ymouse){
    if (!this.drawing){
    this.moveTo(x,y);
    this.drawing = true;
    }else this.lineTo(x,y);
    }else if (this.drawing) this.drawing = false;
    };



    a slightly different way of handling it using key.isdown(1) to check if the mouse is pressed, but nonetheless effective.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center