PDA

View Full Version : Managing Multiple External Classes



spike50
August 1st, 2008, 01:29 AM
Hi,

I'm having some trouble getting mulitple external classes to work simultaneously. I have a little game that is running off the document class. I'd like to add a background scroller. I have an external class for the scroller but I don't know how to make the FLA see this additional AS file. If I make the scroller the doc class, it works fine but of course the game doesn't work. If the game is the doc class, the scroller doesnt work. I've been looking for a good (clear) tutorial on how to manage multiple external classes but have not found anything that tells me the steps how to do it. Can anyone help? Thanks!

M

hasch2o
August 1st, 2008, 04:09 AM
Hey Spike

You can import your scroller class like you import for example fl.display.movieclip. (if it is in the same folder as the .fla and documentclass you don't need to import it)
Then you can create a new object from your class:

var myNewClass:Scroller = new Scroller(); //or something similar

It looks like you should get your basics straight first:
http://www.senocular.com/flash/tutorials/as3withflashcs3/
good tutorial to get you started (you can find tons of others by searching)

hth
Carlo

spike50
August 1st, 2008, 05:32 PM
Thanks for the post. I've tried what you suggest but I get an error message.

I have two AS files: Game.as (the doc class) and Scroll.as. I've added this line to the doc class Game.as:

public var scroller:Scroll = new Scroll();

But I get an 1120 Access of undefined property error message for the mcs fore1 and fore2. But they are there and the Scroll code works fine if I make it the doc class.

Can anyone advise what I'm doing wrong? Thanks!

M

mieff
August 1st, 2008, 08:10 PM
i may be reading this wrong but it looks like you need to import the class before you try to access it. for example:

import yourScrollerClass:

var scrollInstance:yourScrollerClass = new yourScrollerClass();