-
flip-flopper
incorrect number of arguments on a custom class of a MC
Hi folks,
I have a document class called Main that is defined for my main movie. In the library of that movie there is a MovieClip called HomeBlock for which I have written a custom class called HomeBlock that defines its behavior. This HomeBlock class accepts one parameter in the constructor right now, an XMLDocument, and the Main class sends it to HomeBlock in the constructor call like this:
newBlock = new HomeBlock(theXMLdoc);
By the time this line is executed, theXMLdoc will be defined, after it's load has completed, and I know this to be true;
Here is my HomeBlock class:
PHP Code:
package nordberg
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.xml.XMLDocument;
public class HomeBlock extends MovieClip
{
// properties
private var xmlDoc:XMLDocument;
// class movieclips, for reference
// pos1_mc, pos2_mc, ... pos12_mc
// constructor
public function HomeBlock(theXML:XMLDocument)
{
this.xmlDoc = theXML;
createThumbButtons();
}
private function createThumbButtons()
{
for (var i:Number = 1; i <= 12; i++)
{
// add a ThumbButton instance to each posX_mc clip
var ID:String = xmlDoc.firstChild.firstChild.firstChild.firstChild.childNodes[i-1].attributes.imageID;
var url:String = getThumbURL(ID);
trace("about to add thumbButton with ID="+ID+" and URL="+url);
//this["pos"+i+"_mc"].thumbButton = new ThumbButton(url, ID);
// new ThumbButton(thumbURL, thumbID)
// add a dropShadow filter to the instance, match it to the logo's shadow
}
}
private function getThumbURL(imageID:String):String
{
var url:String;
for (var i:Number = 1; i < xmlDoc.firstChild.firstChild.childNodes.length; i++)
{
// iterating through sections
for (var j:Number = 0; j < xmlDoc.firstChild.firstChild.childNodes[i].firstChild.childNodes.length; j++)
{
// iterating through <image> elements
if (xmlDoc.firstChild.firstChild.childNodes[i].firstChild.childNodes[j].attributes.imageID == imageID)
{
url = xmlDoc.firstChild.firstChild.childNodes[i].firstChild.childNodes[j].firstChild.attributes.url;
break;
}
}
if (url != null)
{
break;
}
}
return url;
}
}
}
So problem is when I test the main movie, I get a compile error saying HomeBlock accepts 0 parameters and I have "incorrect number of arguments" in the constructor call.
Can anyone explain? Is Flash somehow still looking at the HomeBlock class that IT created back before I added the custom class definition to HomeBlock and it was creating one on-the-fly which accepted no parameters in the constructor?
Am I not subclassing correctly?
Many thanks...
-
That code looks okay. I notice it is in a package. Are you certain that flash is associating that class file with your symbol?
-
flip-flopper
yes, it is finding the class. i got around the issue by omitting a constructor definition so that it just inherits the MovieClip constructor, and i pass my data in through a second call to another public function to set properties. but i'd prefer to just specify it in the constructor...
and now that i know it is indeed finding the class, this is the compile error i get if i use my first code again as that class:
temp.as 1203: No default constructor found in base class nordberg:HomeBlock.
now THAT makes me think it's not using the class anymore and is writing this temp.as thing. but that makes no sense, because i'm just cutting and pasting new code into the same .as file and commenting out the rest.
i even thought that maybe i needed to use the super() statement in my constructor to ensure the MovieClip constructor is used in compiling with the modifications i've specified, but that throws the exact same compile error. perhaps if i read up more on extending classes, i'll see the issue, but right now i just don't get it....
-
Senior Member
I think one problem is that you cannot add a parameter at any point when you create the Object and give a class path in the library. What you have done then is correct, which is to create a separate function, where you can add the parameter. Generally, try avoiding adding code in the constructor, especially when the class object is a Displayobject and the constructor is executed before the object is added to the movie.
- The right of the People to create Flash movies shall not be infringed. -
-
flip-flopper
cancerinform, is that just the way that Flash works? theoretically, outside of the Flash IDE this should be OK, right? for instance if i wanted to call a Class NOT in the library and load an swf into that instance that then contained my graphics, then i could pass parameters into the constructor in the way that i tried, right?
are there very general principles of OOP that say when it's appropriate or not to set properties via the constructor vs. a separate function?
-
Senior Member
The constructor of the Document class is used to add scripts. There it is safe, although you don't have parameters. Otherwise of course you can add parameters in the constructor, just in your special case, when you use objects from the library not. It all depends on what you are trying to do.
- The right of the People to create Flash movies shall not be infringed. -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|