# \[AS2\] Loading a AS2 class

**URL:** https://forum.kirupa.com/t/as2-loading-a-as2-class/261689
**Category:** Uncategorized
**Created:** [May 29, 2008, 10:14pm UTC](https://forum.kirupa.com/t/as2-loading-a-as2-class/261689 "2008-05-29T22:14:08Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![zuperxtreme](https://avatars.discourse-cdn.com/v4/letter/z/e9a140/32.png) [@zuperxtreme](https://forum.kirupa.com/u/zuperxtreme)
#### Post date: [May 29, 2008, 10:14pm UTC](https://forum.kirupa.com/t/as2-loading-a-as2-class/261689/1 "2008-05-29T22:14:08Z")

</div>

This is so noobish… but how do I link to a AS2 class file?  
Locally I’m doing this:

import com.gskinner.sprites.CollisionDetection;

and in the same dir of the swf I have the whole “com.gskinner.sprites.” directories.

But how I would do it to upload the swf? How do I point to an online as2 class file? 😑

Bah. Thanks.

---

<div class="post-metadata">

### Author: ![creatify](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@creatify](https://forum.kirupa.com/u/creatify)
#### Post date: [May 29, 2008, 11:08pm UTC](https://forum.kirupa.com/t/as2-loading-a-as2-class/261689/2 "2008-05-29T23:08:16Z")

</div>

you can download his example [fla files at this link.](http://www.gskinner.com/blog/archives/2005/10/source_code_sha.html)

Classes are compiled into the swf when the swf is generated/created. So, they aren’t needed on the web server - than can’t be utilized that way. The import statement needs to be in your fla on a frame - and depending on how he has it set up, you either create an instance of the class on the timeline something like: var foo:TheClass = new TheClass(items may need to get passed in there); or, classes can be linked to movieclips within the library - you can right click on a clip in the library and select linkage - and set things there.

Hope this helps.

---

<div class="post-metadata">

### Author: ![zuperxtreme](https://avatars.discourse-cdn.com/v4/letter/z/e9a140/32.png) [@zuperxtreme](https://forum.kirupa.com/u/zuperxtreme)
#### Post date: [May 29, 2008, 11:24pm UTC](https://forum.kirupa.com/t/as2-loading-a-as2-class/261689/3 "2008-05-29T23:24:30Z")

</div>

```auto
import com.gskinner.sprites.CollisionDetection;
speed = 1;
hit = false;
function onEnterFrame() {
    if (CollisionDetection.checkForCollision(leader, room, 255)) {
        leader.gotoAndStop(2);
        hit = true;
    } else {
        hit = false;
        leader.gotoAndStop(1);
    }
    // ******************
    if (Key.isDown(Key.RIGHT)) {
        if (CollisionDetection.checkForCollision(leader, room, 255)) {
            leader._x -= speed
        } else {
            leader._x += speed;
        }
    } else if (Key.isDown(Key.LEFT)) {
        if (CollisionDetection.checkForCollision(leader, room, 255)) {
            leader._x += speed
        } else {
            leader._x -= speed;
        }
    }
    //   
    
    if (Key.isDown(Key.UP)) {
        if (CollisionDetection.checkForCollision(leader, room, 255)) {
            leader._y += speed
        } else {
            leader._y -= speed;
        }
    } else if (Key.isDown(Key.DOWN)) {
        if (CollisionDetection.checkForCollision(leader, room, 255)) {
            leader._y -= speed
        } else {
            leader._y += speed;
        }
    }
    
}

```

That’s my code, but If I upload it to imageshack for example, it doesn’t work. 😕

[http://img81.imageshack.us/my.php?image=singleplayeroverviewxm0.swf](http://img81.imageshack.us/my.php?image=singleplayeroverviewxm0.swf)

I’m trying to find out why the collition detection isn’t working. Locally it does, well… not too good…

---

<div class="post-metadata">

### Author: ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)
#### Post date: [May 30, 2008, 6:15pm UTC](https://forum.kirupa.com/t/as2-loading-a-as2-class/261689/4 "2008-05-30T18:15:56Z")

</div>

does the collision detection happen with dynamically loaded images…? or flash drawn movieclips ?

---

<div class="post-metadata">

### Author: ![zuperxtreme](https://avatars.discourse-cdn.com/v4/letter/z/e9a140/32.png) [@zuperxtreme](https://forum.kirupa.com/u/zuperxtreme)
#### Post date: [May 31, 2008, 5:03pm UTC](https://forum.kirupa.com/t/as2-loading-a-as2-class/261689/5 "2008-05-31T17:03:56Z")

</div>

So far with 2 simple MC’s.

“leader” and “room”.

It works… sort of. If you collide and keep holding the key it won’t go through the wall, BUT if you let go and there’s a collision still taking place you can press the opposing key and you’ll go through the wall…

That’s why I want to upload it, so you guys can see what’s up…
