View Full Version : New to flash. Quick question
cyreb7
07-05-2008, 10:38 PM
I am building my first flash application and I have a problem I hope you can help me with.
I am trying to find a way to “setChildIndex” of a move clip dynamically using a variable, and I don’t have a clue how to do it. Any help would be appreciated.
var order:String = "i am trying to get this variable";
function photoOrder():void {
this.setChildIndex("to go here",-1);
}
DiamondDog
07-05-2008, 10:58 PM
Sounds like you need to put that String inside a TextField, which is a display object.
Once you've got a display object, you can set its index.
var order:String = "i am trying to get this variable";
var myTextField:TextField = new TextField();
myTextField.text = order;
addChild(myTextField);
myTextField.autoSize = TextFieldAutoSize.LEFT;
function photoOrder():void
{
setChildIndex(myTextField,-1);
}
Does that do what you want?
(I'm pretty sure setting the index to -1 like that is actually going to set the index to 0 which is the lowest value index recognised in Flash.)
cyreb7
07-05-2008, 11:50 PM
I think you misunderstand my question. I am trying to set the index of a move clip (not add text).
All I am trying to do is “setChildIndex” of a move clip, but instead of setting the name of the move clip directly, I would like to get the name from a variable.
zwemg
07-06-2008, 12:25 AM
addEventListener(MouseEvent.MOUSE_OVER, focus, false,0,true);
function focus(e:MouseEvent):void {
var myTextField:MovieClip = e.target as MovieClip;
setChildIndex(myTextField, numChildren - 1);
}
This example will set the index via mouse event. Hope this example helps.
What type of interaction is being used to change the index? Keyboard, mouse etc etc
DiamondDog
07-06-2008, 07:45 AM
You're right, I misunderstood the question.
This function will put the movie clip named 'order' at the top of the display list (ie. on top of everything else)
function photoOrder():void
{
setChildIndex(getChildByName(order),numChildren-1);
}
Does that do what you want?
cyreb7
07-07-2008, 03:32 AM
I don’t know if it is something I am saying or what but I don’t seem to be getting my problem across, so let me try to tell you exactly what I am trying to do.
I have 2 move clips on stage and etch one contains a photo,
http://farm4.static.flickr.com/3103/2643769603_7eb796050b_m.jpg
I have it set up so when I click on one of the photos, it calls a function in the movie clip that enlarges the photo to fill the stage. But my problem is when it fills the stage, one of the photos will be on top of the other
http://farm4.static.flickr.com/3278/2644596588_f727fd9e6a_m.jpg
I need to find a way to make it so when I click on the photo it is instantly set on top of all the other movie clips.
Here are some of my ideas on how to accomplish my goal (I haven’t been able to find a way to accomplish any of them).
#1: when I call the function in the movie clip that enlarges the photo, it also sets the movie clip on top of all the others. I don’t know if there is a way to set the z depth of the movie clip from within itself.
#2: when I call the function in the movie clip that enlarges the photo, it also puts the name of the movie clip into a variable in the man time line, than the movie clip would call a function in the man time line that would get the name of the movie clip (stored in the variable), and set that movie clip to the highest z depth. I don’t know how to take the name of the movie clip (stored in the variable) and use it to set the z depth.
If anyone knows a way to accomplish any of these ideas, that would be really helpful. Or if anyone knows a better way to do this that would be greatly appreciated.
lordofduct
07-07-2008, 05:15 AM
didn't turn out to be a quick question did it?
Anyways, that question was technically answered...
Either way.
to set Child index to the top of the display list you can do a couple of things. The two easiest things is:
var myPic1:DisplayObject = /the picture/;
var myPic2:DisplayObject = /another picture/;
var myPicsParent:DisplayObjectContainer = /the object myPic1 and 2 are children of/;
myPicsParent.addChild(myPic1);
myPicsParent.addChild(myPic2);
myPic1.addEventListener(MouseEvent.CLICK, onPicClick);
myPic2.addEventListener(MouseEvent.CLICK, onPicClick);
function onPicClick(e:MouseEvent):void
{
var obj:DisplayObject = e.currentTarget;
//DO scale obj
myPicsParent.addChild(obj);
//OR
myPicsParent.setChildIndex(obj, myPicsParent.numChildren - 1);
}
myPicsParent.addChild(obj);
//OR
myPicsParent.setChildIndex(obj, myPicsParent.numChildren - 1);
both do the same exact thing. By adding the child again it goes to the top of the display list in that displayObjectContainer.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.