all groups > flash actionscript > march 2006 >
You're in the

flash actionscript

group:

OOP problem


OOP problem stephan.k
3/2/2006 10:37:37 PM
flash actionscript:
Hi Forum

I have a very basic OOP problem that so far I have avoided and now the project
is getting slightly out of hand. I'd like to figure this thing out in order to
be able to track down some of the bugs.

Here is goes:

In the following example I always get an error stating that one class
conflicts with the name of another class that was already imported. So far I
have avoided the problem by using the Objects type allowing everything to pass
into the constructor of class B. But this way I can't detect any errors in
class B relating to class A.

What am I doing wrong? somehting's not set up right here. Please someone
help me fix this bug in my brain.

Thanks

Stephan




//-------File Start: "A.as"---------//

import B;

class A(){

private var b:B;

public function A(){
b = new B(this);
}

}
////////////File End////////////




//-------File Start: "B.as"---------//
import A;

class B(){

private var a:A;

public function B(_a:A){}

}
////////////File End////////////
Re: OOP problem stephan.k
3/3/2006 8:47:39 PM
I guess I'm looking for a way to instantiate a class and be able to call
functions in the class that created the function. Is that such a weird idea?

My scenario is:
Have a manager class that coordinates everything. among others it instatiates
a controller class, a data class and a square class. Now I'd like the
controller class to tell the data class about the location of the square and
have the square be able to ask the data class how big it is... and so on.

In order to do that I always pass through the manager class reference when
instatiating the 3 other classes. But I'd like to be able to use the actual
Class Type instead of the Generic Object Type to have the compiler detect all
the errors.





Re: OOP problem myIP
3/4/2006 12:25:57 AM
OOP in Flash is fairly new to me, from what you have posted so far it sounds
like MVC relationship between you classes would be ideal. I do not know much
about the MVC other then it could easily be an overkill for small projects.
What you have in your first class is a Composition relation between it and
class B, which may be all need to do from what you are asking. You can have
the Manager Class create instances of the Controller Class and Data Class and
then have the Square Class to extend off the Data Class.

Read the code below.

Again OOP is fairly new to me so I am just curious if the instance of the
Square will be pulling the correct instance. So I guess in this example you
are using Composition and Inheritance. Some code here may seem irrelevant or
even redundant depending on your project.


//a directory of where all of your classes resides
import allofyourclasses.*

class Manager
{
//x & y properties

public function Manager(width, height, x, y)
{
c:Controller = new Controller(width, height, x, y);
}
}

import allofyourclasses.*

class Controller
{
//some properties
public function Controller(width, height, x, y)
{
d:Data = new Data(width, height, x, y);
}
}


import allofyourclasses.*

class Data
{
//some properties
public function Data (width, height, x, y);
{
//store width & height variables for Square class can retrieve
}

public function objectSize( ):Number
{
//return width & height
}
//use x & y
}


import allofyourclasses.*

class Square extends Data
{
//some properties
public function Square
{

}

private function retrieveSize()
{
super.objectSize( );
}
}


//FLA

m:Manager = new Manager(50, 50, 112.3, 347.2);
s: Square = new Square( );
s. retrieveSize();//returns width and height
AddThis Social Bookmark Button