Actionscript 3: document class Q
- Started
- Last post
- 14 Responses
- CyBrain
This should be a simple one. I'm attempting my first AS3 site, so, I admit I'm a little special.
Here is my code: http://talesfromthehead.com/rand…
I keep getting the error "TypeError: Error #1010: A term is undefined and has no properties.
at Nikkicascone()"What could be wrong with those button functions? I'm totally clueless.
Also,
If anyone can recommend me one of those sites where you can post your code I would appreciate it.
- PonyBoy0
home_mc isn't defined yet... even if it's sitting as a Movieclip on the main timeline... the document class won't see it...
... you need to export that movieClip so it's available in the library then create an instance in the document class like so:
var home_mc: MyHomeMC = new MyHomeMC ;
- PonyBoy0
oh yeah... you have to add that 'home_mc' after you create the instance...
var home_mc: MyHomeMC = new MyHomeMC ;
addChild (home_mc);
... then run your for loop and should sift through the contents and set your buttons
- CyBrain0
Thanks. I'll try that.
Wow, that's very intolerant of AS3 to prohibit movie clips on the timeline from being used like that.
Why did the for loop correctly trace the names of my buttons nested within home_mc?
- satan0
alternatively you can turn on 'automatically declare stage instances' in your fla publish settings and your document class will recognise the mc if it's placed on stage.
- CyBrain0
I'm getting the same error as before 1010: A term is undefined...
http://talesfromthehead.com/rand…
and her is my linkage on home_mc in the library.
I'm stumped.
- acescence0
you're targeting a clip inside a clip inside a clip. your class has no knowledge, nor should it, of home_mc and its contents. home_mc should be its own object, responsible for doing whatever it does all on its own in reaction to events that happen outside of it.
- maybe too early for OOP talk if he can't get a button to workPupsipu
- CyBrain0
turns out I had an instance name wrong. It works if I put linkage on home_mc in the library and attach it. It won't work otherwise.
I'm a suffering AS3 noob but I'm sure you can put buttons that work inside a movie clip. I must be misunderstanding your meaning there.
- Pupsipu0
he means you should not be doing that shit in the document class. You should have a class HomeMC.as that extends movie clip that would handle it's own clicks and button events.
then in the document class you would add homeMC or AboutMC and not see all the event listening crap. Makes it easier to organize things.
- nadnerb0
no need to export for AS or anything for something simple like this! your naming isn't right on the listeners - it should be b1_mc, am i correct? That's where your error is.
- nadnerb0
one other thing - add listeners in the loop, then find out which target they're coming from when you capture the event. i.e.
for (var i:uint = 1; i <= 4; i++) {
home_mc.icons_mc["b" + i + "_mc"].addEventListener(MouseEve... doOver);
}public function doOver(e:MouseEvent):void {
e.target.gotoAndPlay("over");
}
- CyBrain0
I get the feeling that the AS3 Gods don't want nesting of any kind, so I tried to simplify my structure by moving those buttons directly to the stage.
Here is my new document class.
http://talesfromthehead.com/rand…And here are the errors I got for each mention of b1_mc, which is just a movie clip on the stage.
1120: Access of undefined property b1_mc
Since I have import flash.display.MovieClip; at the top of my class, why do I keep getting this error?
- email me your files if you want. I'll get er fixednadnerb
- so are you just trying to make it work instead of doing a few tutorials and looking this shit up on kirupa?Pupsipu
- Dude, I've been on three blog sites, I read ALL of Colin Moock's O'Reilly book and I'm on my first AS site. I'm not a genius.CyBrain
- funkage0
Might sound stupid, but have you named your instance, hit_btn, properly? And you can paste your code here, btw: http://pastebin.com/