all groups > flash actionscript > april 2005 >
You're in the

flash actionscript

group:

syntax checker mistakenly reports error


syntax checker mistakenly reports error lreadl
4/16/2005 12:00:00 AM
flash actionscript:
I defined the following 2 classes in .as files, and saved each under the same
name as its class, in the same folder. class ClassOne { var prop:ClassTwo;
var name:String = 'ClassOne'; function ClassOne() { } } class ClassTwo {
var prop:ClassOne; var name:String = 'ClassTwo'; function ClassTwo() { } }
When I click the Check Syntax button for ClassOne, I get the following error
message: **Error** C:\flash stuff\ClassOne.as: Line 1: The name of this class,
'ClassOne', conflicts with the name of another class that was loaded,
'ClassOne'. class ClassOne { And similarly for ClassTwo. However, I
saved the following ActionScript in a .fla file in the same folder: var
myClassOne:ClassOne = new ClassOne(); var myClassTwo:ClassTwo = new ClassTwo();
trace(myClassOne.prop); trace(myClassTwo.prop); myClassOne.prop = myClassTwo;
myClassTwo.prop = myClassOne; trace(myClassOne.prop); trace(myClassTwo.prop);
trace('Should be ClassTwo: '+myClassOne.prop.name); trace('Should be ClassOne:
'+myClassTwo.prop.name); The syntax checker found no errors, and Publish
Preview produced the expected outputs: undefined undefined [object Object]
[object Object] Should be ClassTwo: ClassTwo Should be ClassOne: ClassOne In
fact, afterwards the syntax check no longer found any errors for the .as files.
Deleting and retyping the 'v' in var on the first line of one of the class
definitions was enough to get the error messages again. Clearly, this
shouldn't happen. Is this a widely-known problem with the syntax checker?
Should I pass this on to Macromedia? Or is there some reason I should not
define classes which have each other as members, even though the .fla files
seems to run fine?
Re: syntax checker mistakenly reports error Jeckyl
4/16/2005 12:00:00 AM
please show your full script for the two .as files .. do you use import or
include ?
--
Jeckyl

Re: syntax checker mistakenly reports error lreadl
4/16/2005 12:00:00 AM
Each class description at the top of my previous post is the full script for
one of the two .as files. The class definition for ClassOne, and only that
class definition, is saved in a file called ClassOne.as. Likewise for
ClassTwo. The script I posted above for the .fla file is the full script for
that file. I wrote it in the ActionScript panel of the first frame of that
..fla file, and there is no other script in the file. I did not use import or
include. Apparently, simply saving the .fla file in the same folder as the two
..as files is enough for the script in the .fla file to be able to create
instances of those two classes.
Re: syntax checker mistakenly reports error Blade alSlayer
4/17/2005 12:00:00 AM
Shouldn't you import ClasTwo in ClassOne.as in irder to use it there?
And another thing - I am not sure if the hole design is correct: when you have
a member of EACH class inside the OTHER there will be infinite loop there:
c1.prop.prop.prop.prop... you should get what I mean... This is just not
possible, I think:)
Re: syntax checker mistakenly reports error lreadl
4/17/2005 12:00:00 AM
Apparently, it's not only possible, but useful in the program I'm writing to
have two classes with instances of each other as members. I do know what you
mean, but it's not an infinite loop. The following script runs, and ends, and
all the comparisons produce 'true': var myClassOne:ClassOne = new ClassOne();
var myClassTwo:ClassTwo = new ClassTwo(); myClassOne.prop = myClassTwo;
myClassTwo.prop = myClassOne; trace(myClassOne.prop.name == 'ClassTwo');
trace(myClassOne.prop.prop.name == 'ClassOne');
trace(myClassOne.prop.prop.prop.name == 'ClassTwo');
trace(myClassOne.prop.prop.prop.prop.name == 'ClassOne'); I'd have to add an
infinite number of .props for the script to loop infinitely. Apparently, the
only problem is with the syntax checker for the .as files. The problem fixes
itself after I run the above script in a .fla file; after running the script,
the syntax checker no longer finds the aforementioned error in the .as files.
Adding import statements changed nothing. So... I guess I should report this
to Macromedia? Am I missing something here? This seems like a mistake on the
part of the syntax checker.
Re: syntax checker mistakenly reports error Blade alSlayer
4/19/2005 12:00:00 AM
Look, in Object Oriented Programming, when you want to have members of class A
inside class A (maybe not directly, but inside another class B, as in your
script) you must use POINTERS. Since Flash hasn't got pointers, maybe it uses a
similar implementation, which is hidden from the user - that I don't know.
But - what is the problem using a real instance of the class: Suppose your
class needs 32 bytes to be stored. Now - if you add an instance of that class
inside it - what have we got - 32+32=64. But that is not all! The "inside"
instance of the class also have its own member of the same class - 32+32+32 =
96, etc. Now do you get what I mean?
Maybe Flash is smart enough to solve this itself, but however in general it is
not a good idea, I think. Better use some kind of simple hierarchy - like use a
Base Class for the data you need in both other classes...
Re: syntax checker mistakenly reports error Jeckyl
4/19/2005 11:37:44 PM
Flash uses (equiv of) pointers which are self managed (reference counting).
That is, once there are no pointers to an object, it deletes itself
automatically. So there is no problem at all in having an instance of an
object inside itself as the poster shows (ie object one as a reference to an
object 2 inside it and object 2 has a reference to object 1.
--
Jeckyl

Re: syntax checker mistakenly reports error Blade alSlayer
4/20/2005 2:13:19 PM
Re: syntax checker mistakenly reports error mpetty
4/20/2005 4:01:06 PM
It appears you essentially have a recursive prototype chain. You are asking the
compiler to create an object member which is an instance of a class, and in the
other class you also have an instance of the previous class.
I don't remember who the original mathematician was who came up with it, but
it's analogous to Farnsworth's Paradox (for Futurama fans out there), universe
A has a box which contains the entire contents of universe B, and universe B
has a box which contains the entire contents of universe A.


Re: syntax checker mistakenly reports error Blade alSlayer
4/20/2005 7:11:12 PM
That was exactly my point!
AddThis Social Bookmark Button