Results 1 to 4 of 4

Thread: z-Index with API objects

  1. #1
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default z-Index with API objects

    I notice coded vecor objects are allways behind librar items place on the stage.

    How do I control that?

    I have a simple drawing script that I have from "Learning ActionScript 3.0 For Beginners" (exellent book BTY)

    it goes like this:
    var drawing:Boolean=false;
    //this.graphics.controllthefriggin Z-INDEXgrrrrrrr
    this.graphics.lineStyle(1,0x000000);
    this.graphics.moveTo(mouseX, mouseY);

    this.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
    stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown, false, 0, true);
    stage.addEventListener(MouseEvent.MOUSE_UP, onUp, false, 0, true);

    function onDown(evt:MouseEvent):void {
    drawing=true;
    }
    function onUp(evt:MouseEvent):void {
    drawing=false;
    }
    function onLoop(evt:Event):void{
    if(drawing){
    this.graphics.lineTo(mouseX, mouseY);
    }else{
    this.graphics.moveTo(mouseX, mouseY);
    }
    }
    I have my background on the stage but the drawing is on the bottom -

    -as a footnote I see many drwing apps don't use a stage object for the drawing board. That could be my first mistake.

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Hey evan...

    -as a footnote I see many drwing apps don't use a stage object for the drawing board. That could be my first mistake.
    That's exactly it. The stage is your basic canvas. When you add anything on top of it, even if it's a background, it lies on top of that canvas.

    So, while you're drawing on the stage probably works, the background is covering it up.

    The trick here as I've suggested in some of your other posts is to create the drawing within a container MC that is placed above the library items.

    In AS3, you do this via setChildIndex(). You can read up on it here.

    Does that help?

  3. The Following User Says Thank You to Medyman For This Useful Post:

    evan (05-27-2008)

  4. #3
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default

    -Yeah, been doing my homework, but thankyou for confirming there is no z-index control with library itmes.What if I import graphics another ie with a script?

    As a matter of fact I got the gist of it from some code samples. For my use , I created a movieclip, set the alpha to zero, then set conditions to stop the drawing activity ON_ROLLOUT which also confines the drawing and allows me to use other functions to test whether the mouse is over that _mc or not.

    I can also code a shape or sprite and declare children thereof.

    I am still stumped with trying to have the user draw and scale an object, then be able to drag it, and resize it again. (-I think there is a clue in the AS3. cookbook chapter 6 which I only skimmed. he pain about that book is it only uses code that gets imported, so the syntax is a little different -having to declare packages and such.)

    -I would have to code it somehow so that the machine remembers it's ID in some way.
    Last edited by evan; 05-27-2008 at 11:04 AM. Reason: update

  5. #4
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    -Yeah, been doing my homework, but thankyou for confirming there is no z-index control with library itmes.What if I import graphics another ie with a script?
    ActionScript doesn't have a z-index in the same terms as CSS. But you can still declare the order in which things lie on the stage. Again, that's what the setChildIndex() method is for. It behaves in much the same way as z-indexing with CSS (higher the number, the higher plane it rests on).

    I can also code a shape or sprite and declare children thereof.
    You can't declare children to shapes, only sprites.

    I am still stumped with trying to have the user draw and scale an object, then be able to drag it, and resize it again.
    You really can't have all of those actions on the same movieclip. Well, you could but it wouldn't make the application of much use or at the very least of very little flexibility. What you should do is to have two three movieclips:

    (from outside to inside)
    1. A container movieclip to hold everything
    2. A movieclip that controls the resizing
    3. A movieclip that holds the drawing.


    -I would have to code it somehow so that the machine remembers it's ID in some way.
    Hmm...? What do you need to do this for? You could set cookies as a sure-fire way to do it. There are also SharedObjects. These are great for local storage but be warned that these *can* be turned off. I doubt many people are technically astute enough to turn them off. But in the same way that javascript is turned off in some corporate environments, so are SharedObjects. More.

  6. The Following User Says Thank You to Medyman For This Useful Post:

    evan (05-27-2008)

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
  •