Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

problem with external as file

Explorer ,
Sep 09, 2008 Sep 09, 2008
Hi everyone

Im currently experimenting with AS3 and I’m trying to attach an external actionscript file to a movie clip in the library
but I keep getting error messages, my .as file worked fine in AS2 and I cant figure out what the problem could be

heres the code in my fla file

var mymc:MovieClip = new Block;
this.addChild(mymc);

trace(mymc._framecount);



and heres my as file code

class Block extends MovieClip
{
public var _blocktype:Number;
public var _framecount:Number;


public function Block()
{_blocktype = 0;
_framecount = 6; }}


And I get the following errors when I run the main fla file

1017 the definition of base class movieclip was not found
5000 the class 'block' must subclass flash.display.MovieClip

I find this strange because AS2 never had this problem with my .as file anyway I did a bit of Goggling and changed the code to

package{
import flash.display.MovieClip;

class Block extends MovieClip
{
public var _blocktype:Number;
public var _framecount:Number;


public function Block()
{_blocktype = 0;
_framecount = 6; }}}

and now I get this error

1080 call to a possibly undefined method Block. var mymc:MovieClip = new Block;
I’ve checked the export for actionscript tick box and the class name is the same Block (capital B), its driving me nuts can anybody please put me out of my misery

TOPICS
ActionScript
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 09, 2008 Sep 09, 2008
You need to make the Block class public, as in:

public class Block extends MovieClip


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 09, 2008 Sep 09, 2008
Bingo thanks mate just tried it, funny how the actionscript 2 version didn’t have a problem with it, is AS3 stricter about public and private declarations
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 09, 2008 Sep 09, 2008
According to 9.1 of the AS 3 spec: http://livedocs.adobe.com/specs/actionscript/3/wwhelp/wwhimpl/js/html/wwhelp.htm

The default visibility for a class is internal (non-dynamic, and non-final).
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 09, 2008 Sep 09, 2008
By the way, that really tripped me up when I wrote my first AS3 class and compiled it with a fla. I would have thought the fla, if in the same directory as the class file, would also be in the default package and thus could reference it (even if it was internal). I guess the fla is not considered to be in the default package.

In AS2, the default visibility of a class was public. (I don't remember if you even can modify a classes visibility in AS 2.)

By the way, I use FlexBuilder to create my classes, even when they will be compiled with the fla. FlexBuilder can create the class outline for you and it will explicitly add public to the text of the file. (Go FlexBuilder 😉
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 10, 2008 Sep 10, 2008
quote:

Originally posted by: jpsoul
By the way, I use FlexBuilder to create my classes, even when they will be compiled with the fla. FlexBuilder can create the class outline for you and it will explicitly add public to the text of the file. (Go FlexBuilder ;-)


Why compile with the fla when Flexbuilder can do that for you?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 10, 2008 Sep 10, 2008
LuigiL,

Sometimes I want to use Flash (the IDE) to create custom skins (assets) that often gets controlled by an app I make in FlexBuilder. Because the assets are created in the Flash IDE I need to compile them with the Flash IDE. Essentially, I use Flash to create a document class or other class that extends movieclip and use those classes to define the movieclip instances they contain. This way an artist can modify those movieclip instances (the artwork) and I can refer to them by their class type and class members.

I don't use the Flash IDE for anything other than setting up the artwork. All logic is scripted with FlexBuilder. In my opinion, the Flash IDE is a very crude scripting tool.

-JP
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 10, 2008 Sep 10, 2008
Basically you don't need any classes in the Flash IDE. A designer just needs to give the assets a linkage identifier and publish a swf. The programmer can then point to the assets in the compiled swf and you can do compiling in Flexbuilder. Very nice workflow.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 10, 2008 Sep 10, 2008
Hi

I’ve just found this whilst looking for info on organizing AS3 projects which kind of explains the reason for the problem

http://www.actionscript.org/forums/showthread.php3?p=787854

now Ive just gota get my head round this document structure thing to really understand it, does anybody know of any good tutorials on the subject?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 10, 2008 Sep 10, 2008
As far as the fla not being able to access classes internal to the default package, this is what I think is going on:
The fla always has a document class. If you don't create one, Flash automatically creates it for you - in memory. That in memory document class is not in the default package and thus would not have access to internal classes of the default package.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 10, 2008 Sep 10, 2008
That's the basic idea. However, I explicitly create the class files that declare the movieclip instances rather than have flash automatically create these classes. This is mainly to provide for substitutable dependencies when doing unit testing. The unit test can use a subclass of the document class that creates stubs for all the movieclip instances, while the production code will use the instances created by Flash. In either case, the test and the production code refers to the document class type (polymorphism allows the subclass to be used instead of its parent class the document class).

I often create a controller class that takes the document class as an argument in the constructor. The controller class provides all the logic and controls the visual assets declared in the document class.

var skin:SomeDocumentClass = loader.content as SomeDocumentClass;
var myController:CustomController = new CustomController(skin);

The controller will do things like add event listeners to movieclips/buttons created in the document class.

This also makes it very easy to change the "skin". I just load a different swf that subclasses the same document class.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 10, 2008 Sep 10, 2008
What framework are you using then for unit testing?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 10, 2008 Sep 10, 2008
FlexUnit

I also use mock4as which is an open source mock object library I helped write: http://code.google.com/p/mock4as/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 10, 2008 Sep 10, 2008
Interesting, but mocksamples.org ... I don't get that one :-)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 10, 2008 Sep 10, 2008
LATEST
Hmmm... I actually didn't add that link or any content to that site. I will follow up with the other guy.

I did however add a developer guide to the wiki: http://code.google.com/p/mock4as/wiki/DeveloperGuide

It's a rough draft which I will be editing in the near future. *** Coming soon... ;o)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines