PDA

View Full Version : constructor arguments for on stage MovieClips


abeall
12-14-2006, 02:21 AM
If I have a class which requires constructor arguments, how do I pass those arguments in when instantiating an instance in the IDE? Example, here is a class:
package{
import flash.display.*
public class MyClip extends MovieClip{
function MyClip(stuff){
trace(stuff);
}
}
}

And in Flash, I have a MovieClip symbol which is associated with the MyClip class. I drag an instance on stage. How do I specify what will be used for 'stuff'? Currently it says:
ArgumentError: Error #1063: Argument count mismatch on MyClip$iinit(). Expected 1, got 0.
at flash.display::Sprite/flash.display:Sprite::constructChildren()
at flash.display::Sprite$iinit()
at flash.display::MovieClip$iinit()

Tink
12-14-2006, 08:08 AM
you'll need to create the instance with AS

the binary
12-14-2006, 08:31 AM
yep, youŽll have to attach them during runtime and pass the parameter
via 'init-object'..

salute

senocular
12-14-2006, 02:03 PM
either that or make the parameter optional and set it afterwards.

abeall
12-14-2006, 04:40 PM
Hm. Thanks.

What I'm trying to do is make a component-like MovieClip that "lives and breathes" on it's own, with many parameters. In AS1/2 I would make a MovieClip that contained ActionScript or was associated with a class, then directly on the MovieClip I would use onClipEvent(load) and set my variables. Same basic functionality as a component, less the (IMO) obese component architecture when creating them. Since code cannot be placed directly on a MovieClip now(how are designeres expected to make simple buttons now???), I can't find a way to avoid having to create components for editable on stage elements. Any resources on how components are built in AS3?

Tink
12-14-2006, 07:20 PM
yep, youŽll have to attach them during runtime and pass the parameter
via 'init-object'..i may be being picky here but i wanted to clarify. there is no attched in AS 3.0, your create a new MovieClip or custom class using the new keyword. therefore u can just pass the params as now, i.e. no init-object.

Once Flash is released u will be able to make components and specify these props in the property panel as you can in AS 2.

abeall
12-14-2006, 07:49 PM
i may be being picky here but i wanted to clarify. there is no attched in AS 3.0, your create a new MovieClip or custom class using the new keyword. therefore u can just pass the params as now, i.e. no init-object.
Got it. Thanks. ex:var mc = new MyClip('this is my stuff');

Once Flash is released u will be able to make components and specify these props in the property panel as you can in AS 2.

In other words, V2 components? But what about all the extending of UIComponent classes? I made a few V1 components, I actually liked how that worked, it was close to what I describe above--simple self contained MovieClips. V2 components are too much work and commitment. You end up with something great if you really want to make something a complete idiot can use, but 99% of the time I just want something very modular that I can re-use and tweak myself from project to project, or other competent Flash designers/developers to do the same. This thread isn't about why I don't like components, but I wonder if some of the things I didn't like about V2 components would still be around in AS3. With V2, you had to import tons of .fla assets from the core UI component classes and extend UIComponent. If I understand correctly, this was mainly done to get the EventListener model and such, but since that is now built into the core AS, can I just make a component that extends Sprite or MovieClip and not worry about everything else? I tried making a V2 component that only extended MovieClip in Flash 8 but didn't know what to do with all the proprietary junk, like the empty constructor, createChildren(), createObject(), init(), move(), invalidate, etc

senocular
12-14-2006, 09:04 PM
Its hard to say what the process will be with AS3 until Flash 9 is released.

abeall
12-14-2006, 10:21 PM
Its hard to say what the process will be with AS3 until Flash 9 is released.

I guess that's reasonable. :) I believe Mike Downey said that they got the likes of Grant Skinner and others to make the components for AS3, so maybe I won't hate them as much.