PDA

View Full Version : Add movieclip from the library with as3


victor1976
02-06-2008, 01:32 PM
Hi,

I'm working on an application that has 2 classes:

Main, which is the DocumentClass. In this class I create an instance of my 2nd class, called WidgetDataProvider.

In this 2nd class, WidgetDataProvider, I want to add a movieclip ('Progressbar') from my library to the stage.

When I use this code:

var pb:Progressbar = new Progressbar();
addChild(pb);


nothing happens..

When I use the same code in my DocumentClass, my movieclip appears.
Can anyone explain this?

Thnx!

fredula
02-06-2008, 02:28 PM
You have to add you class instance to the display list as well.

So in your documnet class you would have this:

var wdp:WidgetDataProvider = new WidgetDataProvider();
addChild(wdp);

that should do the trick :)

victor1976
02-06-2008, 03:29 PM
THnx, that worked.

Now, to make it a bit more complicated:
In my DocumentClass I added another movieclip 'widget', and added it to the displayList.

Is it possible to acces this 'widget' movieclip from my 2nd class 'WidgetDataProvider'?

For instance, if I use this code in WidgetDataProvider class:


var pb:Progressbar = new Progressbar();
widget.addChild(pb);


...i get the error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.

panel
02-06-2008, 03:54 PM
You should pass is as constructor param


var widget:Widget = new Widget();
var wdp:WidgetDataProvider = new WidgetDataProvider(widget);
addChild(wdp);

funkybudda
02-06-2008, 03:57 PM
hi,

I was just about to ask this question, glad this has been answered. However, in my project I need to add multiple instance of the class from library dynamically, I know how to do it in AS2 way, can anyone elighten me with AS3 way, specifically with this new addchild(movieclip) function?


thanks!

panel
02-06-2008, 08:47 PM
for(var i:Number=0; i<10; i++)
{
var movieclip:MovieClip = new MovieClip();
addChild(movieclip)
}

graphicguru_india
05-25-2011, 12:55 PM
Hi,
I'm interacting external swf's, each swf's having icons, each icon will repeat in some swf's. I am handling them through the main movie where these external swf's loading on a movie clip of main movie.
I separated group of icons for each swf's.
say first swf have icon1, icon2,icon3, icon4, icon5
second swf have icon2, icon4,icon6, icon7,icon8
third swf have icon1,icon3,icon4,icon6,icon9,icon10
these icons are listed in Main movie and when user hove on the icon from the list of main movie, the respective icon will sclaed in external swf.

Now i have divided the listed icons mc into three for each swf. im getting an error but not line or code. simple it says
frame2() null or object not found.
Please help me onthis guys, thanks in advance.