Hey Guys,
I’m currently trying to teach my self OOP and am having a little trouble. I have very little scripting experience and none other than actionscript so I’m sorry if this is poorly explained.
I’m working on a calendar component with a little code-based animation. I have a super class (called calendar.as) and in the constructor I would like to instantiate a sub class called loadNewMonth() (called loadNewMonth.as). For help purposes, I shrunk both classes to the relevant information:
//In calendar.as
class calendar {
private var __loadNewMonth:loadNewMonth
function calendar() {
__loadNewMonth = new loadNewMonth()
loadNewMonth.loadNewMonth()
}
}
//In loadNewMonth.as
class loadNewMonth {
public function loadNewMonth {
trace("Sub-Class Instantiated")
}
}
I can’t seem to get the trace to run. Does anyone know what I’m doing wrong? I believe the syntax is correct so maybe this is just the wrong way to go about it?
Thanks in advance,
Kyle
You wouldn’t call loadNewMonth.loadNewMonth(); loadNewMonth() is the constructor call, what is run when you use new loadNewMonth() <- that is essentially the function (plus the creation of the object).
This may be a stupid question, but are you creating a calendar instance?
I am creating a calendar instance in the .fla at run-time. I want to call loadNewMonth() in calendar’s constructor. All methods that are part of the calendar class run as they are supposed to, I just can’t figure out why loadNewMonth() won’t run. I have tried declaring the class and then simply calling loadNewMonth() but I can’t get that to work either. I’m sorry if I’m getting the jargon wrong, this is my first OOP project.
Would you be able to quickly whip up a working example based off of my previous example? So I might be able to compare a working version with a non-working one?
Nevermind, I read your tutorial: http://www.kirupa.com/developer/oop2/AS2OOPindex.htm
Helped me figure it out plus like 20 other problems I was having.