Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 12-17-2006, 02:17 PM   #1
picklejar
Registered User
 
picklejar's Avatar
 
Join Date: Jan 2005
Posts: 31
Default addChild and depth

Hi,

This is most likely sooo stupid but cannot get me old beefcake round this.

I am having a bit of trouble getting to grips with how the new addChild in AS3 works. If I have a class which creates a video object and adds it to the stage, I cannot work out how to add a rectangle I have created over the video object, it just shows up behind. So in AS2 this would be a depth issue, how does it work in AS3?

Add the video:

Code:
var video:Video = new Video();
            addChild(video);
Draw me a rectangle:

Code:
private function drawRectangle():void {
			
                 var myMatrix:Matrix = new Matrix();
			
			var type:String = GradientType.LINEAR;
			var colors:Array = [0x000000, 0xFFFFFF];
                 var alphas:Array = [100, 100];
                 var ratios:Array = [0, 0xFF];
			var boxWidth:Number = 320;
		 	var boxHeight:Number = 240;
		 	var boxRotation:Number = Math.PI/2; //90 degrees
			var tx:Number = 0;
		 	var ty:Number = 200;

            myMatrix.createGradientBox(boxWidth, boxHeight, boxRotation, tx, ty);

            graphics.beginGradientFill(type, colors, alphas, ratios, myMatrix);
            graphics.lineTo(0, 240);
            graphics.lineTo(320, 240);
            graphics.lineTo(320, 0);
            graphics.lineTo(0, 0);
        }
Now when the NetStream buffer is empty I wanna run the drawRectangle method and place the rectangle above the video???

I looked at the previous depth post in this forum which states:

Code:
setChildIndex(blah blah);
Would this work in Flash 9 (silly question again I am sure), or is it relevent for Flex only?

Cheers S

Last edited by picklejar; 12-17-2006 at 02:24 PM.
picklejar is offline   Reply With Quote
Old 12-17-2006, 02:38 PM   #2
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

setChildIndex is AS3; it will work in both Flex and Flash 9. The things in Flex that won't work in Flash 9 are the mx packages and their contents (classes etc). setChildIndex is core to the language and not mx.
__________________
(6)
senocular is offline   Reply With Quote
Old 12-17-2006, 02:38 PM   #3
Tink
Addict
 
Tink's Avatar
 
Join Date: Nov 2001
Location: London
Posts: 2,128
Default

you'll need to draw your rectangle inside a Sprite and then add that to the displayList at an index greater than your Video object.

graphics by convention always appear beneath the displayList
Tink is offline   Reply With Quote
Old 12-17-2006, 02:47 PM   #4
picklejar
Registered User
 
picklejar's Avatar
 
Join Date: Jan 2005
Posts: 31
Default

Mah many thanks to you both, one final q, previous if I wanted to add a MC at a certain depth I would do say myMc.attachMovie(...and add a depth here..); is this similar in fashion to add to an index in the displayList then?

p.s. Tink hey up hows life? Ny frequents back to the lovely city of Leicester
picklejar is offline   Reply With Quote
Old 12-17-2006, 02:49 PM   #5
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

addChildAt

only you cannot add children at a position greater than the length of the display list (i.e. there can be no empty depths between display objects)
__________________
(6)
senocular is offline   Reply With Quote
Old 12-17-2006, 02:59 PM   #6
picklejar
Registered User
 
picklejar's Avatar
 
Join Date: Jan 2005
Posts: 31
Default

Cool chaps thanks !
picklejar is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:23 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.