View Full Version : 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.
Medyman
05-25-2008, 05:00 PM
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 (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html#setChildIndex()).
Does that help?
-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.
Medyman
05-27-2008, 01:49 PM
-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 (http://drawlogic.com/2008/01/10/howto-sharedobjects-for-local-storage-as3/).
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.