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.