Applying a custom class to an object in the document class

How’s it going guys. I just started learning Actionscript 3.0 and so far not bad. However, I’m having trouble applying custom created classes to objects in the main document class. I’m using Flash as the application, however there is no timeline scripting involved. I loaded the document class called Main.as:

package
[COLOR=#000000]{[/COLOR]
[COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]display[/COLOR].[COLOR=#993300]MovieClip[/COLOR];
[COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]net[/COLOR].[COLOR=#000000]URLRequest[/COLOR];
[COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]display[/COLOR].[COLOR=#000000]Loader[/COLOR];

[COLOR=#993300]public[/COLOR] [COLOR=#993300]class[/COLOR] Main [COLOR=#993300]extends[/COLOR] [COLOR=#993300]MovieClip[/COLOR]
[COLOR=#000000]{[/COLOR]
    [COLOR=#993300]private[/COLOR] [COLOR=#993300]var[/COLOR] _redBox:Loader = [COLOR=#993300]new[/COLOR] Loader[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
    [COLOR=#993300]private[/COLOR] [COLOR=#993300]var[/COLOR] _redBoxLink:URLRequest = [COLOR=#993300]new[/COLOR] URLRequest[COLOR=#000000]([/COLOR][COLOR=#0000ff]"images/redbox.jpg"[/COLOR][COLOR=#000000])[/COLOR];
    [COLOR=#993300]public[/COLOR] [COLOR=#993300]var[/COLOR] buttonScaleHover:ButtonScaleHover = [COLOR=#993300]new[/COLOR] ButtonScaleHover[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
    
    [COLOR=#993300]public[/COLOR] [COLOR=#993300]function[/COLOR] Main[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]
    [COLOR=#000000]{[/COLOR]
        _redBox.[COLOR=#000000]x[/COLOR] = [COLOR=#000000]100[/COLOR];
        _redBox.[COLOR=#000000]y[/COLOR] = [COLOR=#000000]100[/COLOR];
        _redBox.[COLOR=#993300]load[/COLOR][COLOR=#000000]([/COLOR]_redBoxLink[COLOR=#000000])[/COLOR];
        addChild[COLOR=#000000]([/COLOR]_redBox[COLOR=#000000])[/COLOR];
    [COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]

[COLOR=#000000]}

[/COLOR]Now, what I’m trying to do is apply this class named ButtonScaleHover.as to the _redBox in the document class. Here is the code for ButtonScaleHover:

package
[COLOR=#000000]{[/COLOR]
[COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]display[/COLOR].[COLOR=#000000]Sprite[/COLOR];
[COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]events[/COLOR].[COLOR=#000000]MouseEvent[/COLOR];

[COLOR=#993300]public[/COLOR] [COLOR=#993300]class[/COLOR] ButtonScaleHover [COLOR=#993300]extends[/COLOR] Sprite
[COLOR=#000000]{[/COLOR]
    [COLOR=#993300]private[/COLOR] [COLOR=#993300]var[/COLOR] [COLOR=#993300]_xScale[/COLOR]:[COLOR=#993300]Number[/COLOR];
    [COLOR=#993300]private[/COLOR] [COLOR=#993300]var[/COLOR] [COLOR=#993300]_yScale[/COLOR]:[COLOR=#993300]Number[/COLOR];
    
    [COLOR=#993300]public[/COLOR] [COLOR=#993300]function[/COLOR] ButtonScaleHover[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]
    [COLOR=#000000]{[/COLOR]
        [COLOR=#993300]trace[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]"The ButtonScaleHover Class is being loaded"[/COLOR][COLOR=#000000])[/COLOR];
        [COLOR=#993300]_xScale[/COLOR] = [COLOR=#993300]this[/COLOR].[COLOR=#000000]scaleX[/COLOR]
        [COLOR=#993300]_yScale[/COLOR] = [COLOR=#993300]this[/COLOR].[COLOR=#000000]scaleY[/COLOR]
        [COLOR=#993300]this[/COLOR].[COLOR=#000000]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000000]ROLL_OVER[/COLOR], [COLOR=#993300]onRollOver[/COLOR][COLOR=#000000])[/COLOR];
        [COLOR=#993300]this[/COLOR].[COLOR=#000000]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000000]ROLL_OUT[/COLOR], [COLOR=#993300]onRollOut[/COLOR][COLOR=#000000])[/COLOR];
    [COLOR=#000000]}[/COLOR]
    
    [COLOR=#993300]public[/COLOR] [COLOR=#993300]function[/COLOR] [COLOR=#993300]onRollOver[/COLOR][COLOR=#000000]([/COLOR]event:MouseEvent[COLOR=#000000])[/COLOR]:[COLOR=#993300]void[/COLOR]
    [COLOR=#000000]{[/COLOR]
        [COLOR=#993300]this[/COLOR].[COLOR=#000000]scaleX[/COLOR] *= [COLOR=#000000]2[/COLOR];
        [COLOR=#993300]this[/COLOR].[COLOR=#000000]scaleY[/COLOR] *= [COLOR=#000000]2[/COLOR];
    [COLOR=#000000]}[/COLOR]
    
    [COLOR=#993300]private[/COLOR] [COLOR=#993300]function[/COLOR] [COLOR=#993300]onRollOut[/COLOR][COLOR=#000000]([/COLOR]event:MouseEvent[COLOR=#000000])[/COLOR]:[COLOR=#993300]void[/COLOR]
    [COLOR=#000000]{[/COLOR]
        [COLOR=#993300]this[/COLOR].[COLOR=#000000]scaleX[/COLOR] = [COLOR=#993300]_xScale[/COLOR];
        [COLOR=#993300]this[/COLOR].[COLOR=#000000]scaleY[/COLOR] = [COLOR=#993300]_yScale[/COLOR];
    [COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]

[COLOR=#000000]}[/COLOR]

I tried using
_redBox.[COLOR=#000000]ButtonScaleHover[/COLOR]COLOR=#000000[/COLOR];in the document class after i added it to the display object list. However, it didn’t work. Basically, I’m just trying to apply a custom class to an object(in this case the loader). Thank you guys very much in advance.

I don’t ask for much. A little help, please? :slight_smile:

I think the lack of responses is due to the strange phrasing of your question.

There isn’t really any process that could be described as “applying” a class to an object. Once an object is created/instantiated, it always retains the same datatype. The code that you provided doesn’t really make sense, since you are treating the ButtonScaleHover constructor as though it were a method of the Loader class, which it isn’t.

With the small amount of code in your current ButtonScaleHover class, it would be possible to make ButtonScaleHover a subclass of Loader instead of Sprite. After doing that, you could change your code so that _redBox becomes a ButtonScaleHover: private var _redBox:ButtonScaleHover = new ButtonScaleHover();

Thank you very much Krilnon, that definitely did the trick. However, another question has risen from this.

I thought the whole purpose of creating classes was so that you can apply it to an object. So what you’re basically trying to say is that the only way to apply custom classes is to instantiate as an object?

Let’s say I make a custom class that is a MouseEvent. How would I go applying that to an object in the document class? Which is basically what I was trying to do in the first place.