Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




AddChild() And Arrays



Howdy,

I'm trying to make a submenu using an mc and just calling it via addChild().

I've got a movieclip "box" and it's been set up in the linkage to export to actionscript / export in first frame.

I've declared:


Code:
var button01:box = new box();
.
.
.
var button06:box = new box();

about_BTN.addEventListener(MouseEvent.MOUSE_DOWN, aboutBTN);
outside of any function, at the top of the actionscript.

further down I have the function:


Code:
function aboutBTN(event:MouseEvent):void
{
// trace("CLICKED ON ABOUT BUTTON");

var startX:Number = 196.3;
var startY:Number = 128.0;
var buttonName:Array = new Array;

for (var num = 1; num <= 6; num++)
{
buttonName[num] = "button0" + num.toString();

addChild(buttonName[num]); // <--- cause of the error

// buttonName[num].x = startX;
// buttonName[num].y = startY;
// startY += 30;

}
}
The error I receive is this (because of the addChild(buttonName[num]):


Quote:




TypeError: Error #1034: Type Coercion failed: cannot convert "button01" to flash.display.DisplayObject.
at pierviewV02_wb_fla::MainTimeline/aboutBTN()




Any ideas, or a more efficient way to do this?


Thank you.

~Wyl



FlashKit > Flash Help > Actionscript 3.0
Posted on: 02-08-2008, 11:25 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Arrays And Addchild
Hi,

I have a load of movieclips that have the custom base class called 'Card'. I want to make an array of their names and add them to my stage

var list:Array = new Array("comedyFront", "casinoFront");

for (var j:int = 0; j < list.length; j++)
{
var myMovieClip:Card = new Card(list[0]);
this.addChild(myMovieClip);
}

any ides how I do this? The error is

1137: Incorrect number of arguments. Expected no more than 0.

Error 1061: Undefined Method AddChild... AddChild Problem
1061: Call to a possibly undefined method addChild through a reference with static type flash.displayisplayObject.

Hi, i have searched the forum recently but even i've found some similar problems i could not find any answer that meet my problem.

Well i had a gallery MovieClip and a sprite called photoContainer which i add some thumbs (my thumb class). Everything was perfectly working until i delete my gallery movieClip on the stage and make it a class from the library (class name : Gallery) I wanted to add photoContainer sprite into my gallery using gallery.addChild(photoContainer) so that way i thought when i say removeChild(gallery) both gallery and everything inside it including photoContainer will be removed. But now i can't add anything to my photoContainer sprite which is inside of gallery.

//my working code before i deleted gallery movieclip on stage

ActionScript Code:
var photoContainer:Sprite =  new Sprite();
photoContainer.name="photoContainer";
addChild(photoContainer);
photoContainer.addChild(thumb); //perfectly works
photoContainer.mask=gallery.thumb_holder;

//the code i used after i had deleted gallery movieClip

ActionScript Code:
var gallery:Gallery = new Gallery();
addChild(gallery as MovieClip);

var photoContainer:Sprite =  new Sprite();
photoContainer.name="photoContainer";
gallery.addChild(photoContainer);
photoContainer.mask=gallery.thumb_holder;
/*
gallery.getChildByName("photoContainer").addChild(thumb); //gives "1061: Call to a possibly undefined method
addChild through a reference with static
type flash.display:DisplayObject."

gallery.photoContainer.addChild(thumb); //gives TypeError: Error #1010: A term is undefined and has no properties.
*/


by the way:

ActionScript Code:
trace("gallery Type : " +gallery); //gallery type : [object Gallery]
trace("photo container type  : " +gallery.photoContainer); //photo container type  : undefined

trace("photo container type  : " +gallery.getChildByName("photoContainer"))

//photo container type  : [object Sprite]

it perfectly adds photoContainer to gallery but gallery.photoContainer returns undifined?? or when i use "gallery.getChildByName("photoContainer").addChild (thumb);" it gives error 1061 Can anybody help me?

thanks you very much...

Is There A Way To Add Variable Arguments To AddChild.. Like AddChild(blah, {x:30})?
in AS2 you could so something like:

blah = attachMovieClip("something", "whatever", {_x:30, _y:25, blahVar:90});

and it would immediately position the blah movieclip, and add a variable called blahVar set to 90 within it, which could be accessed like:

trace(blah.blahVar);

is there any way of doing this in AS3? addChild only takes one argument it seems, so i find myself being forced to do crap like this:

addChild(someMovie);
someMovie.x = 20;

and i have absolutely no idea how to add variables to a movieclip either.. does anyone have any idea?

OOP Addchild Problem "undefined Method Addchild"?
Trying to do more OOP...

This is within a Movieclip class in a .as file:




public static function iconLoad(section:String){
var iconLoader:Loader;
iconLoader = new Loader();

var myDispatcher:IEventDispatcher = iconLoader.contentLoaderInfo;
myDispatcher.addEventListener(Event.COMPLETE, completeIconListener);
myDispatcher.addEventListener(ProgressEvent.PROGRE SS, progressIconListener);
iconLoader.load(new URLRequest("photos/"+section+"/icon.jpg"));
trace("photos/"+section+"/icon.jpg");
var image:Bitmap;
function completeIconListener(event:ProgressEvent):void{
image = Bitmap(event.target.loader);
image.smoothing = true;
addChild(image);
image.x = 0;
image.y = 0;
engage();
}

function progressIconListener(event:ProgressEvent){
iconBytesLoaded = event.bytesLoaded;
iconBytesTotal = event.bytesTotal;
}
}


Why do I get this error for addchild()?
1180: Call to a possibly undefined method addChild.

Arrays In A Text File To Arrays In Flash
What i am wanting to do is get an array list from an external file and put it into flash arrays, the code i tryed to use was this:


PHP Code:



            for (i=1; i<33; i++) {
                
                if(id=="undefined" || id=="NaN"){
                    
                } else {
            
                id[i] = id(i)

                               }

                         } 




But that dosent work obviously.

I know ive got the
PHP Code:



id[i] 




bit right, but i dont know how to do the bit from the text file.

in the file it goes like this:


PHP Code:



id1=432&id2=324 ect 




So basically what i am trying to ask is how to in a look do variables using the i (id plus the i at the end). Anyone got any ideas?

Sorting Arrays...2-Dimensional Arrays
How would I go about sorting two dimensional arrays using the sort() function. What I'd like to do is organize the arrays inside of an array by a certain variable...

i.e:

array1 = new Array("Name", "State1", "Cost");
array2 = new Array("OtherName", "AnotherState", "OtherCost");
array3 = new Array("DifferentName", "YetAnother", "AndAnother");
allarrays = new Array(array1, array2, array3);

Now, let's say I want to sort the arrays in allarrays by their state variable. In other words, I want to sort them so allarrays would look something like this (if sorted by state):

allarrays:
array2,
array1,
array3

Any suggestions or past experiences with this sort of sorting? Would I use the Sort() fuction? or would I have to make my own sort function? Thanks in advance for any help you can provide.

Arrays: Cleaning Up Empty Arrays
Hi,
So, I have an array generator, and its not worth explaining the details, but long story short, I end up with an array in which some of the slots are "undefined". How can I go through and remove just those slots? Eg this this my Array

myArray[1] = "red"
myArray[2] = "blue"
myArray[3] = undefined
myArray[4] = "pink"
myArray[5] = "undefined

and what I want to end up with is:

myArray[1] = "red"
myArray[2] = "blue"
myArray[3] = "pink"

thx!

-Z

Arrays/Arrays/Arrays/and Functioning.
Can someone please , tell me how to shorten that Rescale function to just do all the movies in one shot ? and also to add an array for the delay which is the ( o.2, 0.4,0.6 ) so i need to shorten all this to do something like this


Code:
rescale = function(){
this.scaleTo(100,2,"easeOutElastic",this.speed);
this.alphaTo(100,2,"linear",this.speed);
}
//... the next line is inserted within the duplicate movie loop
eval("item"+a).speed = 0.2*a


Instead of all this..

Code:
// Callback Function for lacos to tell when to rescale/alpha back to 100 percent
reScale = function(){
//How can I shorten this by just making an array and doing this in One shot ? is the only problem
item0.scaleTo(100,2,"easeoutElastic",0.2);
item0.alphaTo(100,2,"linear",0.2);
item1.scaleTo(100,2,"easeoutElastic",0.4);
item1.alphaTo(100,2,"linear",0.4);
item2.scaleTo(100,2,"easeoutElastic",0.6);
item2.alphaTo(100,2,"linear",0.6);
item3.scaleTo(100,2,"easeoutElastic",0.8);
item3.alphaTo(100,2,"linear",0.8);
item4.scaleTo(100,2,"easeoutElastic",1);
item4.alphaTo(100,2,"linear",1);
item5.scaleTo(100,2,"easeoutElastic",1.2);
item5.alphaTo(100,2,"linear",1.2);
item6.scaleTo(100,2,"easeoutElastic",1.4);
item6.alphaTo(100,2,"linear",1.4);
item7.scaleTo(100,2,"easeoutElastic",1.6);
item7.alphaTo(100,2,"linear",1.6);
item8.scaleTo(100,2,"easeoutElastic",1.8);
item8.alphaTo(100,2,"linear",1.8);
item9.scaleTo(100,2,"easeoutElastic",2);
item9.alphaTo(100,2,"linear",2);
item10.scaleTo(100,2,"easeoutElastic",2.2);
item10.alphaTo(100,2,"linear",2.2);
item11.scaleTo(100,2,"easeoutElastic",2.4);
item11.alphaTo(100,2,"linear",2.4);
item12.scaleTo(100,2,"easeoutElastic",2.6);
item12.alphaTo(100,2,"linear",2.6);

};

//Duplicate method puts all movieclips on stage at 0 alpha so the user doesnt see the placement
for (a=0; a<titles.length; a++) {
duplicateMovieClip("item", "item"+a, a+1);
//eval("item"+a).alphaTo(0,0,null);
eval("item"+a).item_txt.text = titles[a];
eval("item"+a).tween("_x", [posX[a]], 4, "easeoutElastic");
eval("item"+a).tween("_y", [posY[a]], 4, "easeoutElastic", 0.1);
//Callback function is set here
eval("item"+a).scaleTo(0,0.2,"easeoutElastic",0.1,reScale);
item._visible = false;
}

AddChild
PHP Code:



var addStar:starOuter = new starOuter();var StringI:String;var RandomY:Number; for(var i = 0; i <= 50; i++){    RandomY = Math.round(Math.random() * 265);    StringI = "Star" + String(i);    addChild(addStar).name = StringI;    getChildByName("StringI").y = RandomY;    }





I use this code, and it gives error.


Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Untitled_fla::MainTimeline/Untitled_fla::frame1()
I realy don't know what is the problem, 'cos i have seen this type of use of getChildByName .

AddChild
Hello all.
I created a xml based menu using display objects.
I create a simple for each loop with every xml entry and then use the addchild method.

The problem is, there is no way to identify the menu item. What I mean, is that every display object has the same name.
I thought that maybe I could use arrays, and create a display object with an id… nothing works.

How on earth can I identify the menu items so that I may then change color with the ColorTransform or use javascript functions??

Here is my loop, just in case (I want to identify the rect45 object):

PHP Code:



var d:int;        for each (var item in newBar.menuXML.item) {                        //CREATES MENU BAR            var menu01 = new menuBarItem();            menu01.x = d * 30;            menu01.y = -44;            menu01.buttonMode = true;            addChild(menu01);            //CREATES MENU BAR FILL            var rect45 = new barTint();            rect45.x = 0;            rect45.y = 0;            menu01.addChild(rect45);            var colorInfo:ColorTransform = rect45.transform.colorTransform;            var themeColor = newBar.menuXML.color;            function mouseHover(event:MouseEvent):void            {                colorInfo.color = themeColor;                rect45.transform.colorTransform = colorInfo;            }            function mouseLeave(event:MouseEvent):void            {                colorInfo.color = 0x616161;                rect45.transform.colorTransform= colorInfo;            }            rect45.addEventListener(MouseEvent.MOUSE_OVER, mouseHover);            rect45.addEventListener(MouseEvent.MOUSE_OUT, mouseLeave);            //CREATES MENU BAR TEXT AND EMBEDS FONT FOR ROTATION            var menuTitle:TextField = new TextField();            menuTitle.text = item.label;            menuTitle.x = d * 30 + 15;            menuTitle.y = 75;            menuTitle.embedFonts = true;            menuTitle.rotation = -45;            menuTitle.setTextFormat(format);            menuTitle.width = 105;            menuTitle.selectable = false;            menuTitle.mouseEnabled = false;            addChild(menuTitle);            d++;        }

What Exactly Does AddChild Do?
i know what defining a class does.
but what i dont kunderstand is, why you have to say this:

PHP Code:



var yourObject:YourClass = new YourClass;




AND

PHP Code:



addChild(yourObject);




the first code instanciates the class, right? why addChild?
what happens if u dont use addChild, but just the first part?
and what happens if u use addChild twice?

AddChild
I am new to as3 so this may sound like a silly question...

I want to be able to display the number result of the variable 'moneycounter' on the stage. If I trace the string 'total' I get the right results but why can't I put it on the stage?

var moneycounter:Number = 0;
var total:String = new String();
total = String(moneycounter);
stage.addChild(total);


error
1067: Implicit coercion of a value of type String to an unrelated type flash.displayisplayObject.

AddChild?
Hi,

Im trying to addChild to stage inside a container but nothing appears on the stage, what do I need to do, and what do I need to do to the artwork MCs so the AS picks them up?:

var container1:MovieClip = new MovieClip();

container1.addChild(artwork1);
container1.addChild(artwork2);
container1.addChild(artwork3);

AddChild? MC?
How do I add an MC from my library to the stage using and external AS file?

AddChild()
I am pretty much making a slide show for the most part. I am adding every image to my movie clip that I have loaded from an xml file. So every image that I load goes straight into my movie clip as so:


Code:
m_bSmoothImage = Bitmap(m_cMovieInstance.GetImage(m_iIndex).content);
m_bSmoothImage.smoothing = true;
m_aBmpArray.push(m_bSmoothImage);
m_iIndex++;

m_mcFrames.addChild(m_aBmpArray[m_iIndex]);
My question is after I add all of my images to my movie clip how do I go about showing them? By using addChild() for every new image that I load will show which works great but I don't know how to say start the slide show all over again without re-adding them.

OOP AddChild
Hi. Newb here with a couple of questions if I may...

I've just started out with AS3 and am having a bit of a problem managing the stage. I've made a base class called "Baddy" for all my enemies, and am trying to make an "AddToScene" member that basically adds a Baddy to the stage's main display list.

However, I don't know where the hell I should actually get the stage variable from so I can call addChild on it to make my Baddy visible. My Baddy class inherits Sprite but it's obviously not the one in there.

I think the code I'm looking for is globalsomething.stage.addChild(this); or something.

I thought I'd work around this for now whilst I find my feet and just not inherit Baddy from Sprite and use .graphics to draw a box, but of course there isn't a global .graphics either.

Is it common practice to put the Main class into a global and deref that all over ? Doesn't seem very OOP.

Is there a standard book I need ? I bought "ActionScript 3.0 Animation" on reccomendation but found it wanting. I've been a game programmer for 20 years so don't need to know about springing and collision detection, but I clearly need much help with the absolute basics of the language/environment itself.

I know this is fundamental, but I'm stumped a bit. Any help would be gratefully received, thanks.

Help Me With AddChild()
I'm making a class that will draw box. The class is created through instances and is not the document class. For some reason I can't get it to show anything.

I'm guessing my problem is that I haven't attached my_sprite to something that is being displayed.

PHP Code:



package {
    import flash.display.Sprite;
    import flash.display.Shape;
    
    public class Make_box {
        private var container:Sprite;
        private var my_sprite:Sprite;
        
        public function Make_box() {
            container = new Sprite();
            my_sprite = new Sprite();
            my_sprite.graphics.beginFill( 0x660000 );
            my_sprite.graphics.drawRect( 0, 0, 100, 140 );
            container.addChild( my_sprite );
            container.x = 275;
            container.y = 200;
        }
    }


AddChild()
what does the addChild function do? im trying to move on from AS2 to AS3 and i see this function a lot in samples and tutorials. to me it appears that it adds a movieclip to the stage or to another movieclip, but can't you just do that by mc.attachMovie()?

AddChild Help
I really wanna do this:

(("holder_holder_")+i).addChild(holder_array[i]);

is there any way???


happy thanksgiving!!

AddChild() Help
Hi everyone.

what I´m tying to do is:

the code above is simplified;


Code:
var adversario:MovieClip;

var ing:Array = ["time1","time2","time3","time4"];

function adicionaAdversario():void
{
switch (meuCampeonato) //in this case, meuCampeonato is "ing".
{
case "ing":
adversario = new ing[0]();
break;
}
addChild(adversario);
adversario.y = stage.stageHeight - 20;
adversario.x = stage.stageWidth * 0.5;
}
as you can see adversario = new ing[0](); has a wrong syntax.
what I trying to do is give adversario the value of the first position of my array.

sadly it doesnt work and I have no idea how to make it work.

I know that adversario = new time1(); Will work.

but I dont want to type it all because my array will increase...

Using AddChild In OOP
Hello...

I'm having trouble using the addChild() function in .as files.
The class is supposed to setup a scene of movieclips, based on an multidimenstional array, which should refer to the movieclips in my library.
The script file Setup.as looks like this:


Code:
package {

import flash.display.MovieClip;
import flash.events.Event;

public class Setup extends MovieClip{

public var _mcArray:Array = new Array();

public function Setup(_sceneNr):void{

// name x y scene
_mcArray[0] = ["Background1", 0, 0, 1];
_mcArray[1] = ["Background2", 0, 0, 2];
_mcArray[2] = ["Background3", 0, 0, 3];
_mcArray[3] = ["Background4", 0, 0, 4];

// Multidimensional array legend:
// _mcArray[x][0] = MC Name
// _mcArray[x][1] = MC x position
// _mcArray[x][2] = MC y position
// _mcArray[x][3] = Scene

for (var i:Number = 0; i<_mcArray.length; i++){

if (_mcArray[i][3] == _sceneNr) {
var mc:_mcArray[i][0] = new _mcArray[i][0]();
mc.x = _mcArray[i][1];
mc.y = _mcArray[i][2];
addChild(mc);
}
}
}
}
}
but the line "var mc:_mcArray[i][0] = new _mcArray[i][0]();" doesn't work. Should I do it in a different way?

Another problem is, if I change the line to "var mc:Background1 = new Background1();", it is supposed to insert the movieclip Background1 in (X,Y)(0,0) on the stage with "addChild(mc);", but it doesn't. At least, it isn't visible, because it can be traced afterwards.

I'm just starting to learn OOP and AS3, so it's all quite confusing

Thanks.

AddChild Above Everything?
How can I add a child that is going to be above everything? (AS3)

I know the Code is something like this:


ActionScript Code:
setChildIndex(myMovieClip,numChildren-1);

But if I run this code:


ActionScript Code:
setChildIndex(h,numChildren-1);
gamelevel.addChild(h)


I get the error

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/setChildIndex()
at Heli()


Please help thanks
macco

AddChild Bug
Hi

Yesterday I have discovered that addChild method of DisplayObject is not working as expected. While adding new child to displayList it ignores override for width/height getters.

It can be very confusing. Imagine you have image gallery witch displays images in row. Now you wanna mask 3 of them to make only 3 of them visible at time and create some scroll. If you are using some advanced layout system (let’s say you wanna center your image gallery) natural step it to override get width/get height properties, so mask size will be returned instead.

Any ideas for bypass?

AddChild(); Help
Hello,
I'd like to know how to contain sprites with other sprites, and then, control their propeties (eg alpha() within the container.

Here is my code:


ActionScript Code:
var container:Sprite = new Sprite();
container.addChild(inner1);
container.addChild(inner2);
container.addChild(inner3);
container.addChild(inner4);
addChild(container);

How can i control their alpha?

ActionScript Code:
container.addEventListener(Event.ENTER_FRAME, container_func);

function container_func(event:Event):void
{
    container.alpha = 0;
}

Its not working...

AddChild Help
Hi,
I'm new to Flash and action script and wonder if somebody could explain something to me.

With regards to adding a child- if I enter the names of the objects the
child is added.

eg.
gameboard_mc.tga1_mc.addChild(event.target);


but is there a way to refer to the 'gameboard_mc.tga1_mc' portion from a string.


ie
var myString:String = "gameboard_mc.tga1_mc";
myString.addChild(event.target);


Sorry if it's a silly question, but I appreciate any help.


Thanks

Help With AddChild
I use the following code, but the movie is not replaced by the loaded one, as expected:

stop();
var myLoader:Loader=new Loader ();

var myURL:URLRequest=new URLRequest("intro.swf");
myLoader.load(myURL);
addChild(myLoader);


skip_btn.addEventListener(MouseEvent.CLICK, skipButton);
function skipButton(myevent:MouseEvent):void {
var myURL:URLRequest=new URLRequest("home.swf");
myLoader.load(myURL);

stop();
addChild(myLoader);
}


Also how do I stop all external FLVs from playing (in FLVplayers) when new movie loads?

TIA.
David

AddChild
in order to attach a myClip to stage i use the standard

ActionScript Code:
var mClip:MovieClip = new myClip();
addChild(mClip);

but is it possible to refer to myClip (which is the name in the library) and not have to change it to mClip
basically i want to rename things as least as possible

thanks

AS3 And AddChild
Hi,

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?

AS3: AddChild()
I'm just getting into AS3 and it is making me crazy. All over the place (help files etc.) I see code like this.

addChild(myLoader);

Where myLoader is an instance of the Loader class. But it could be a Sprite or something else. But to what are we adding the child? It seems that Loader inherits like this (has anybody else noticed that copying from the help files never seems to work on the first try?):

Loader DisplayObjectContainer InteractiveObject DisplayObject EventDispatcher Object

And it seems that addChild() is inherited from the DisplayObjectContainer class. So is the addChild adding the loader to itself?

AS3 AddChild() To What?
I'm trying to figure out this new DisplayObject list and stuff. I wanted to make some random boxes and put them on the stage – which works great. Then I decided I would like to drag them around – again no problem. Then I decided I would like the one I clicked on to come to the front – big problem.

I'm really wondering when I do something like addChild(sprite) or what ever, what am I adding to it to? I thought it was stage, but that isn't it. Evidently after a loooonnggg time of trying to understand the help files, I figured out that it was the

[object MainTimeline]

Whatever that was. And that I could use "this" in my click handler because they happened to be the same scope. But I imagine at some point they won't be the same. So how do I reference [object MainTimeline].

I guess it is the same issue as AS2 with root and that I could use:

var home=this;

And then later use:

home.setChildIndex(event.target,home.numChildren-1);

Mostly I think typing this up has helped me work out a lot of this. But if anybody has any pointers, please share.







Attach Code

for (var i:int=0; i<10; i++) {
var sprite:Sprite=new Sprite();
sprite.name="mySprite"+i.toString();
var bmpd:BitmapData=new BitmapData(40,80,false,Math.random()*0xffffff);
var bmp:Bitmap=new Bitmap(bmpd);
addChild(sprite);
sprite.addChild(bmp);
sprite.x=i*sprite.width;
}

stage.addEventListener(MouseEvent.MOUSE_DOWN,dragSprite);

function dragSprite(event:MouseEvent):void {
this.setChildIndex(event.target,this.numChildren-1);
event.target.startDrag();
stage.addEventListener(MouseEvent.MOUSE_UP,releaseSprite);
}

function releaseSprite(event:MouseEvent):void {
stopDrag();
}

AddChild
hi!
i try to use addChild in this way, but my flash tell me only »1180 - bla bla«. i don't know why, so i hope anybody could help me. here is some code:

package reapro.buehne
{
import flash.text.TextField;

public class ReTab
{
public static function tabelle(i:int, was:String, wer:String, wann:String, wieviel:String, dank:String):int
{
var list:TextField = new TextField();
list.multiline = true;
list.htmlText = "<a href="event:track1.mp3">Track 1</a><br>";
// HERE WE ARE:
addChild(list);

trace(k, ".
", wer, was, wann, wieviel, dank);
return i;
}
}
}

thank you for any help.

AddChild
I need to load in a movieClip from my library using AS2. I know how to link my movieClip and put it on the stage in AS3, but what can I use instead of addChild and removeChild to perform the same task in AS2.
Thanks
Ryan

The AddChild
I downloaded a scrollbar that works fine when I drag it onto a stage or in a movieclip, and then drag the movieclip containing the scrollbar on to the stage, but when I try to use addChild to the movieclip that contains the scrollbar it gives me this error.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Scrollbar()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at _photo_mc()
at _work_mc/frame105()
But when I call the same movieclip without the scrollbar it loads in fine. I have tried everything, but I cant figure it out. My only guess now is the scrollbar calls a separate .as file and maybe I need to call the .as file in the same function I use to bring in the movieclip containing the scrollbar. If anyone knows how to fix this, that would be great.
Thanks in advance









Attach Code

//my code for my addChild

stop();

var photos:_photo_mc = new _photo_mc

photo_btn.addEventListener(MouseEvent.CLICK, onClick)

function onClick(event:MouseEvent):void
{
addChild(photos)
photos.sb.init(photos.txt_mc, "easeOutBack",2,false,1.5);
photos.x = -45
photos.y = -400
}

//my code in the movieclip that contains the scrollbar and txt_mc

var imageShadow:DropShadowFilter = new DropShadowFilter();
imageShadow.color = 0x000000
imageShadow.blurX = 20
imageShadow.blurY = 20
imageShadow.angle = 0
imageShadow.distance = 0


var my_loader:Loader = new Loader



var prevLoader:_loader_mc = new _loader_mc();
prevLoader.x = 565
prevLoader.y = 165

my_loader.filters = [imageShadow]

my_loader.load(new URLRequest("images/photography/image3.jpg"))
addChild(prevLoader)
my_loader.x = 310

my_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onClick)
my_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete)

txt_mc.prev1.addEventListener(MouseEvent.CLICK, onClick)
txt_mc.prev2.addEventListener(MouseEvent.CLICK, onClick)
txt_mc.prev3.addEventListener(MouseEvent.CLICK, onClick)
txt_mc.prev4.addEventListener(MouseEvent.CLICK, onClick)
txt_mc.prev5.addEventListener(MouseEvent.CLICK, onClick)
txt_mc.prev6.addEventListener(MouseEvent.CLICK, onClick)




function onClick(event:Event):void
{
shadow_mc.visible = false

if(event.target == txt_mc.prev1)
{
my_loader.load(new URLRequest("images/photography/image1.jpg"))
addChild(prevLoader)
my_loader.x = 310
}
else if(event.target == txt_mc.prev2)
{

my_loader.load(new URLRequest("images/photography/image2.jpg"))
addChild(prevLoader)
my_loader.x = 310
}
else if(event.target == txt_mc.prev3)
{
my_loader.load(new URLRequest("images/photography/image3.jpg"))
addChild(prevLoader)
my_loader.x = 310
}
else if(event.target == txt_mc.prev4)
{
my_loader.load(new URLRequest("images/photography/image4.jpg"))
addChild(prevLoader)
my_loader.x = 400
}
else if(event.target == txt_mc.prev5)
{
my_loader.load(new URLRequest("images/photography/image5.jpg"))
addChild(prevLoader)
my_loader.x = 400
}
else if(event.target == txt_mc.prev6)
{
my_loader.load(new URLRequest("images/photography/image6.jpg"))
addChild(prevLoader)
my_loader.x = 310
}
}

function onComplete(event:Event):void
{shadow_mc.visible = true
shadow_mc.gotoAndPlay(2);
removeChild(prevLoader)
addChild(my_loader)
//my_loader.x = 310
}

AddChild -
Hi
I am trying to change the position of a movie clip which is acting as a menu and loading other swfs onto the stage
The problem is, is that the movie clip is also animated and when an swf is loaded the movie clip appears underneath the loaded swf. Can you suggest what method i should use to change the heirachy of this movieclip.

Thanks very much
help is sincerley appreciated

AddChild Within AddChild?
I have a addchild within addchild, simplified;

var mama = new effect_pj_8_rotate();
addChild(mama);
var baby = new letter_pj_8_rotate();
mama.addChild(baby);

Now the Library item letter_pj_8_rotate contains a text field with instance name `lettervalue`. If I add the following line

mama.baby.lettervalue.text = "w";

It doesn`t set the text field to letter "w" but gives output
TypeError: Error #1010: A term is undefined and has no properties.
at PJ_8_rotate/::frame1()

Anybody see any syntax error?

AddChild
I am adding a child when a button is clicked, everything is working fine but it keeps adding a new child every time the button is clicked. How can I prevent this if I only want one child on the stage?

Thanks,
fs_tigre

Addchild
hi all


I am in the MovieClip .
When I open Action panel ; I was wrote
Code:
addChild(button2);
And that was error because I did't have button2 in my MovieClip .
But
I have button2 on the stage .


Thanks advance .

AddChild()
I'm having trouble getting sprites to show up when I add them to other display containers.

I copied and pasted the example from Flex2 Language Reference into Flash and nothing happend except it did output the various numbers like it was supposed to.

Here's my code


ActionScript Code:
import flash.display.Sprite;
 
var container1:Sprite = new Sprite();
var container2:Sprite = new Sprite();
 
var circle1:Sprite = new Sprite();
circle1.graphics.beginFill(0xFFCC00);
circle1.graphics.drawCircle(40, 40, 40);
circle1.graphics.endFill();
 
var circle2:Sprite = new Sprite();
circle2.graphics.beginFill(0x00CCFF);
circle2.graphics.drawCircle(80, 40, 40);
circle2.graphics.endFill();
 
container2.addChild(container1);
container1.addChild(circle1);
container1.addChild(circle2);
 
trace(container1.numChildren); // 2
trace(container2.numChildren); // 1
trace(circle1.numChildren); // 0
trace(circle2.numChildren); // 0
 

How To Use AddChild From Other Class
I have two classes

Code:
package{
import flash.display.Sprite;
public var cell:Sprite;
public class Class_1 extends Sprite{


public function Class_1() {
cell=new Cell();
cell.x=x;
cell.y=y;
addChild(cell);
getChildAt(0);//works
}
}

public class Class_2 extends Sprite{
public function Class_2() {
getChildAt(0); // doesn't work
}
}


What should I do to have access to my display objects from other class, not from main? Please write a code if you know how to solve this problem.

AddChild And LoadMovie Help Please
K,

I am switching to AS3 and I need some help understanding something.

I normally like to have an empty MC that I load external swf files into when I am working on a project.

In AS2 I would do it like this.

myButton.onRelease = function(){
myemptyMC.loadMovie("myswf.swf");
}

Now the cool thing about that was if I loaded a different swf file into the empty movieclip it would just replace the swf that was loaded in before it.

No in as the to load a swf I have to create a new loader and URLRequest. I totally understand how to do that. My problem is that using addChild() does not replace the swf that is already loaded into the empty MC it just places another instance of the new swf file that is being loaded in on top of the swf file that is there.

so if I do myemptyMC.addChild(mySwfLoader); does not replace the content of that movieclip.

How do I do that or how do I remove the content of the movieclip in order to load in my new swf file?

thank

AddChild In For Loop
Hi, can someone tell me how to do it:
[code=actionscript]

private function init_mc(_container){
_envir = new Enviroiment()
for (var i=0;i<3;i++){
var _newMC:MovieClip = new ball
_container.addChild(_newMC)
mcArray.push(_newMC)
_newMC.x = 100*i

_envir.init(mcArray[i],10-i*50,-100,0)
}

[/code]

when i trace (_newMC) i have "instance5,instance7,instance9" but i want name of this mc,
what i do wrong... only one mc is using _envir.init() why...

AddChild In A Loop ...
Hi, how to do this in AS3?

for (var i = 0; i<YY; i++) {
for (var j = 0; j<XX; j++) {
_root.map.attachMovie("Tile","tile_"+i+"_"+j,depth ++,{_x:j*tileSize, _y:i*tileSize});
_root.map["tile_"+i+"_"+j].gotoAndStop(mapArray[i][j]);
}
}

I tried something like

for (var i:uint=0; i < XX; i++) {
for (var j:uint=0; j < YY; j++) {
var newTile:Tile = new Tile;
tileArray.push(newTile);
// tried some addChild stuff here, but failed.
}
}
... where tileArray is a two-dimensional array. Tile is a MoveClip object in the library, containing several frames.

Any suggestions?

Problems With AddChild()
Ive been using AS2 for about a year, and just picked up AS3 about a week ago.

I am working on a little slideshow for some girls who know nothing of computers. It takes pictures out of a database so they can add and remove pictures as needed. I have finally figured out how to load the pictures and then throw the references into an array.

I then made a custom class , Slideshow, that extends Sprite. The picture array is passed to the constructor, and each reference is called as needed.

The problems seem to be occuring in my Slideshow class. It is most certainly my lack of understanding in AS3 that is causing this.


Code:
var TheShow:Slideshow = new Slideshow(PicRefs);
TheShow.width = 500;
TheShow.height = 400;
TheShow.x = 50;
TheShow.y = 60;

addChild(TheShow);



When this code is finished running, the main timeline reports one child instance, but for some reason, the height and width of TheShow are both zero, but x and y are 50 and 60 respectively.

So, needless to say, nothing is showing up on the stage when I play my movie.

Any ideas?

Thanks

Please Help AddChild Is Confusing
Hey all,

I am newers to as3 but used as1/2 lots.

In as3 I have successfully attached movieclips to the screen doing somethign like this :


Code:
addChild(new Ball);
But that requires I've made my own Ball class. How do I attach an object from my library that doesn't have a class file (ie. ball.as).

For example, I have a banner I want at the top of my screen. There is no code required at all for the banner. I just want the image to appear on the screen. In the FLA, I went into the Linkage settings for the banner and gave it a class name of "Banner".

I then tried to do this :


Code:
addChild(Banner);
and it compained it didn't know what Banner was. I then added


Code:
public var FloatingGoldText:MovieClip = new MovieClip();
to the code. it didn't complain about any errors.... but nothing was displayed.

What am I missing?

Thanks so much for any help you can give!!

Ryan

I Just Don't Get AddChild. Why Is It So Confusing To Me :(
I'm goign crazy over here. I've been programming in flash for years... but something so simple has me lost.

I created a simplebutton in my library. In this button I added a dynamic text field. I gave it an instance name of "score". I gave the button a linkage class name of "UpgradeButton".

I created a "UpgradeButton.as" file and put the standard event handlers in it for dealing with onpress and such.

Then I tried to create a new instance of the button... I did :


Code:
var myUpgradeButton = new UpgradeButton();
var test:* = myInterface.addChild(myUpgradeButton);
Ok, now all I want to do is change the dynamic text field on this button. I've tried :


Code:
myUpgradeButton.score.text = "1000";
and


Code:
test.score.text = "1000";
and I've tried adding the code inside the UpgradeButton.as in the contructor such as :


Code:
this.score.text = "1000";
or


Code:
score.text = "1000";
no matter what i try it says :


Code:
ReferenceError: Error #1069: Property score not found on UpgradeButton and there is no default value.
Please help me. I obviously am not undertstanding the way as3 puts grpahic elements on the screen.

Thanks so much!

Ryan

AS3: AddChild From An AS File
Hello,

I have a fla file with a MovieClip named Billy (class: Billy, Base Class: flash.display.MovieClip) linked to Billy.as.

I am trying to get .as file to add an instance of the MovieClip Billy onto the stage with no luck. If anybody can help me here, Thank You! I am not getting any error messages, just a blank swf file...

this is the code in Billy.as. The fla file is blank.

package
{
import flash.display.MovieClip;
import Billy;

public class Billy extends MovieClip
{
private var _billy:Billy;

public function Billy()
{
_billy = new Billy();
addChild(_billy);
}
}
}

Addchild And .as File
Situation;
C:/file.fla
C:/classes/dollar/comp.as

In file.fla a component MC with linkage classes.dollar.comp

If I drag component to stage. all works perfercly.

If instead I do


Code:
var child = new classes.dollar.comp();
addChild(child);
I get error 1120: Access of undefined property classes.
I'm making some simple mistake?
P.

AddChild Issue
Hi,

i have a MovieClip exported as CLangMenu:
i display it onto stage and i want to add next children to this MovieClip.

for that i have the following code:

Code:
var LgMenu:CLangMenu = new CLangMenu();
LgMenu.x = Lang.x;
LgMenu.y = Lang.y+Lang.height;
LgMenu.visible = false;
LgMenu.addEventListener(MouseEvent.MOUSE_OVER, DisplayLangMenu);
LgMenu.addEventListener(MouseEvent.MOUSE_OUT, HideLangMenu);
this.addChild(LgMenu);

var Lg1:CustomButton = new CustomButton(this.Display(lg,'Lg_English'));
Lg1.x = LgMenu.x + 10;
Lg1.y = LgMenu.y + 10;
Lg1.SetOverSound(CClickSound);
Lg1.SetTextFormatOver(myFont,10,0xFAC81E,true);
Lg1.SetTextFormatOut(myFont,10,0x5078B4,true);
LgMenu.addChild(Lg1);


i've tested Lg1 by just changing LgMenu.addchild(Lg1) to this.addchild(Lg1) and it works correctly.
so why LgMenu.addchild(Lg1) does not add Lg1 (extended sprite) to movieclip LgMenu ?

thanks a lot,

A.

AddChild From AS File
Hello everyone, Iam newbie in AS3,
I would like if there is possible to make addChilds from library inside a class, and call the class on timeline actionscript (and not with a document class).
With this code, the box dont show in screen:

//the initCube class :
package {
import flash.display.MovieClip;
public class InitCube extends MovieClip {
public var myMovie:MovieClip;
// the contructor
public function InitCube() {
trace('class initialized');
}
// the cube function
public function CreateCube()
{
myMovie = new Box();
addChild(myMovie);
trace(myMovie.name);
}

}
}

//the box class, linkage cube symbol in library: Box
package{
import flash.display.MovieClip;
public class Box extends MovieClip{
public function Box(){
trace('box initialized');
}
}
}

// in my fla project on timeline:
var myCube:InitCube = new InitCube();
myCube.CreateCube();

it trace :
class initialized
box initialized
instance2

but the library asset dont show in stage, and the trace say it exists.
an idea?

Copyright © 2005-08 www.BigResource.com, All rights reserved