Skip to main content
Participant
February 6, 2007
Answered

A member attribute was used incorrectly

  • February 6, 2007
  • 9 replies
  • 756 views
I want to load an image inside a class. This is my class:

class B
{
private mclListener:Object;
private image_mcl:MovieClipLoader;

function B() {
createEmptyMovieClip("image_mc", getNextHighestDepth());
mclListener = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
image_mc._width = 100;
};
image_mcl = new MovieClipLoader();
image_mcl.addListener(mclListener);
}

public function loadit() {
image_mcl.loadClip("pic.jpg", image_mc);
}
}


This is my fla:
var theB:B = new B();
theB.loadit();

I get the following errors:
B.as: Line 3: A member attribute was used incorrectly.
public mclListener:Object;
B.as: Line 4: Attribute used outside class.
public image_mcl:MovieClipLoader;

What do these mean?
How do I load image inside a class?
This topic has been closed for replies.
Correct answer Peter Lorent
See attached code.

9 replies

February 6, 2007
> In your opinion. ;-)
Oops, and probably a lot of other peoples opinions too, in case that's a virtue.
Inspiring
February 6, 2007
> In your opinion. ;-)
Not an issue of opinion.
February 6, 2007
> Not the issue. It's simply wrong to do so.
In your opinion. ;-)
February 6, 2007
I gotcha, you pass it. I don't think I would have a conscious problem just extending even if I'm only using one method, but that's interesting none the less.
Participant
February 6, 2007
Thanks LuigiL - works a treat - your a star.
February 6, 2007
... where does "target" come from?
Participant
February 6, 2007
Added an onLoadError like so:

mclListener.onLoadError = function(target_mc:Object, errorCode:String) {
trace("Error");
trace(errorCode);
};

it never gets there - no trace messages

I tried it with and without "extends MovieClip". Makes no difference.
Inspiring
February 6, 2007
See attached.

Inspiring
February 6, 2007
target comes from:
var image:B=new B(this);
passing the _root in (or any movieclip you want)
February 6, 2007
> Only extend the MovieClip Class if you need all or most of the functionality of the
> super class.
I plead ignorance. How would he use createEmptyMovieClip without extending the MovieClip class?
Peter LorentCorrect answer
Inspiring
February 6, 2007
See attached code.

February 6, 2007
beats me. listen for the onLoadError event.
Inspiring
February 6, 2007
>>2) You are going to need to extend MovieClip because you are using a MovieClip method(createEmptyMovieClip)
Bad advice after 3). He's wrapping the functionality of the movieclip class in image_mc. So now he's using composition.
Only extend the MovieClip Class if you need all or most of the functionality of the super class.
February 6, 2007
1) You need to use the 'var' keyword, ex: private var
2) You are going to need to extend MovieClip because you are using a MovieClip method(createEmptyMovieClip)
3) You will also need to declare private var image_mc:MovieClip
Participant
February 6, 2007
Okay, changes made. No errors now, but also no image.