# How do you reference/code OOP for as3?

**URL:** <https://forum.kirupa.com/t/how-do-you-reference-code-oop-for-as3/275792>\
**Category:** flash\
**Created:** [November 18, 2008, 6:04pm UTC](https://forum.kirupa.com/t/how-do-you-reference-code-oop-for-as3/275792 "2008-11-18T18:04:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Star258](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@Star258](https://forum.kirupa.com/u/Star258)\
**Post date:** [November 18, 2008, 6:04pm UTC](https://forum.kirupa.com/t/how-do-you-reference-code-oop-for-as3/275792/1 "2008-11-18T18:04:45Z")

</div>

I had this file working flawlessly when it was it was a single .flv file, but I need to code part of the code with oop and be able to reference it with my original .flv file. I am hopelessly stuck and quite new to flash any help would be great.

Thanks,

This is the code I have to call my OOP from the .flv file

apple\_mc.x=stage.stageWidth / 1.5;  
apple\_mc.y=stage.stageHeight / 7;

import keys;  
var Keys:keys = new keys();

* * *

This is what I have for my OOP

package {  
import flash.display.MovieClip;  
import flash.display.Stage;  
import flash.events._;  
import flash.ui._;

public class keys extends MovieClip {  
public function keys(){  
trace(“flashes”);

//apple\_mc.x = stage.stageWidth / 1.5;  
//apple\_mc.y = stage.stageHeight / 7;

var speedY:Number = 0;  
var speedX:Number = 0;  
var radius:Number = apple\_mc.height / 2;  
var friction:Number = .91;

var ax:Number = 0;  
var ay:Number = 20;  
var gravity:Number = 0.5;

//addEventListener(MouseEvent.MOUSE\_DOWN, appledrop);

function appledrop(e:MouseEvent):void {  
this.addEventListener(Event.ENTER\_FRAME, applefall);  
}

addEventListener(MouseEvent.MOUSE\_DOWN, appledrop);  
function applefall(e:Event):void {

speedY += gravity;  
speedY += ay;  
speedX += ax;

speedY \*= friction;  
speedX \*= friction;  
apple\_mc.y += speedY;  
apple\_mc.x += speedX;

if (apple\_mc.y + radius \> stage.stageHeight) {  
apple\_mc.y = stage.stageHeight - radius;  
speedY \*= -1;  
} else if (apple\_mc.y - radius \< 0) {  
apple\_mc.y = radius;  
speedY \*= -1;  
}  
if (apple\_mc.x + radius \> stage.stageWidth) {  
apple\_mc.x = stage.stageWidth - radius;  
speedX \*= -1;  
} else if (apple\_mc.x - radius \< 0) {  
apple\_mc.x = radius;  
speedX \*= -1;  
}  
}

addEventListener(KeyboardEvent.KEY\_DOWN, keyDownHandler);  
addEventListener(KeyboardEvent.KEY\_UP, keyUpHandler);  
function keyDownHandler(e:KeyboardEvent):void {  
switch (e.keyCode) {

case Keyboard.LEFT :  
ax = -0.5;  
break;

case Keyboard.RIGHT :  
ax = 0.5;  
break;

case Keyboard.UP :  
gravity = 0;  
ay = -0.5;  
break;

case Keyboard.DOWN :  
ay = 0.5;  
break;  
}  
}

function keyUpHandler(e:KeyboardEvent):void {  
gravity = 0.5;  
ax = 0;  
ay = 15;  
}

}}  
}
