# How to Create Reusable Classes

**URL:** <https://forum.kirupa.com/t/how-to-create-reusable-classes/268032>\
**Category:** flash\
**Created:** [August 8, 2008, 1:33pm UTC](https://forum.kirupa.com/t/how-to-create-reusable-classes/268032 "2008-08-08T13:33:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fs\_tigre](https://avatars.discourse-cdn.com/v4/letter/f/edb3f5/32.png) [@fs\_tigre](https://forum.kirupa.com/u/fs_tigre)\
**Post date:** [August 8, 2008, 1:33pm UTC](https://forum.kirupa.com/t/how-to-create-reusable-classes/268032/1 "2008-08-08T13:33:09Z")

</div>

[FONT=Calibri][SIZE=3][COLOR=darkred]Hi,[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=darkred]I have a quick question. I am just starting to use classes I have no experience, the only experience I have is basically from reading books.[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=darkred]I would like to create classes for standard components like Glow, Scale… or even create shapes, or simply thing that can be reused.[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=darkred]The question is how can I create a class and use it directly from my .fla file without using the Linking or the DocumentClass option in flash?[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=darkred]For instance, I created this class below that works just fine if I attach it to an object using the linking option in flash, but what I want to do is be able to use it without having to attach it. I would like to be able to call it from the first key frame of my .fla and assign it to an object. I have tried placing this code in the first key frame but it doesn’t work.[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3]import ScaleIt;[/SIZE][/FONT]

[FONT=Calibri][SIZE=3]myObject.addEventListener(MouseEvent.CLICK, Shrink);[/SIZE][/FONT][FONT=Calibri][SIZE=3]function Shrink(evt:MouseEvent):void{[/SIZE][/FONT]  
[FONT=Calibri][SIZE=3]myObject.ScaleItDown()[/SIZE][/FONT]  
[FONT=Calibri][SIZE=3]}[/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=darkred]How can I do this? I know that the scaling percentage will be the same for all instances using this class but it is fine. Help please!!![/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=darkred]Thanks,[/COLOR][/SIZE][/FONT]  
[FONT=Calibri][SIZE=3][COLOR=darkred]fs\_tigre[/COLOR][/SIZE][/FONT]

[FONT=Consolas][SIZE=3]package {[/SIZE][/FONT]  
[SIZE=3][FONT=Consolas]//import gs.TweenMax;[/FONT][/SIZE]  
[SIZE=3][FONT=Consolas]import gs.TweenLite;[/FONT][/SIZE]  
[SIZE=3][FONT=Consolas]//import gs.TweenFilterLite;[/FONT][/SIZE]  
[SIZE=3][FONT=Consolas]import fl.motion.easing.\*;[/FONT][/SIZE]  
[SIZE=3][FONT=Consolas]import flash.display.MovieClip;[/FONT][/SIZE]  
[SIZE=3][FONT=Consolas]import flash.events.MouseEvent;[/FONT][/SIZE]

[SIZE=3][FONT=Consolas]public class ScaleIt extends MovieClip {[/FONT][/SIZE]

[SIZE=3][FONT=Consolas]public function ScaleIt():void {[/FONT][/SIZE]  
[SIZE=3][FONT=Consolas]this.addEventListener(MouseEvent.CLICK, ScaleItDown);[/FONT][/SIZE]  
[SIZE=3][FONT=Consolas]this.addEventListener(MouseEvent.MOUSE\_OVER, ScaleItUp);[/FONT][/SIZE]  
[SIZE=3][FONT=Consolas]}[/FONT][/SIZE]

[SIZE=3][FONT=Consolas]public function ScaleItDown(event:MouseEvent):void {[/FONT][/SIZE]  
[SIZE=3][FONT=Consolas]TweenLite.to(this, .2,{scaleY:.5, scaleX:.5});[/FONT][/SIZE]  
[SIZE=3][FONT=Consolas]}[/FONT][/SIZE]  
[SIZE=3][FONT=Consolas]public function ScaleItUp(event:MouseEvent):void {[/FONT][/SIZE]  
[SIZE=3][FONT=Consolas]TweenLite.to(this, .2,{scaleY:1.5, scaleX:1.5});[/FONT][/SIZE]  
[SIZE=3][FONT=Consolas]}[/FONT][/SIZE]  
[SIZE=3][FONT=Consolas]}[/FONT][/SIZE]  
[FONT=Consolas][SIZE=3]}[/SIZE][/FONT]
