Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-14-2010, 03:38 PM   #1
robmcmon
Member
 
Join Date: Mar 2009
Posts: 62
Default mutilple classes

I'm trying to import one file which has two pacakges but I'm getting two errrors.
The first error is about a bracket and the second is something along the lines of only having one visible definition... heres the code:

ActionScript Code:
package code{     import flash.events.Event;     import flash.events.MouseEvent;     import flash.display.MovieClip;     import flash.display.SimpleButton;     public class Interactivity1 extends MovieClip {         public var up:Boolean=false;         public var down:Boolean=false;         public var left:Boolean=false;         public var right:Boolean=false;         public var mode:Boolean=true;         public var speed:Number=7;         public function Interactivity1() {             up_btn.addEventListener(MouseEvent.MOUSE_DOWN,pressHandler,false,0,true);             down_btn.addEventListener(MouseEvent.MOUSE_DOWN,pressHandler,false,0,true);             left_btn.addEventListener(MouseEvent.MOUSE_DOWN,pressHandler,false,0,true);             right_btn.addEventListener(MouseEvent.MOUSE_DOWN,pressHandler,false,0,true);             up_btn.addEventListener(MouseEvent.CLICK,clickHandler,false,0,true);             down_btn.addEventListener(MouseEvent.CLICK,clickHandler,false,0,true);             left_btn.addEventListener(MouseEvent.CLICK,clickHandler,false,0,true);             right_btn.addEventListener(MouseEvent.CLICK,clickHandler,false,0,true);             toggle_btn.addEventListener(MouseEvent.CLICK,clickHandler,false,0,true);             addEventListener(Event.ENTER_FRAME,enterFrameHandler);         }         // Event Handling:         protected function enterFrameHandler(event:Event):void {             curve.visible=! mode;             if (mode) {                 if (up) {                     beetle.y-=speed;                     beetle.rotation=0;                 }                 if (down) {                     beetle.y+=speed;                     beetle.rotation=0;                 }                 if (right) {                     beetle.x+=speed;                     beetle.rotation=90;                 }                 if (left) {                     beetle.x-=speed;                     beetle.rotation=270;                 }             } else {                 if (up) {                     go(0);                 }                 if (down) {                     if (beetle.rotation>=0) {                         go(180);                     }                     if (beetle.rotation<0) {                         go(-180);                     }                 }                 if (right) {                     if (beetle.rotation>=0) {                         go(90);                     }                     if (beetle.rotation<0) {                         go(-270);                     }                 }                 if (left) {                     if (beetle.rotation>0) {                         go(270);                     }                     if (beetle.rotation<=0) {                         go(-90);                     }                 }             }             // Loop to opposite side of the masked area             // when the beetle travels off-screen.             if (beetle.y<0) {                 beetle.y=0;             }             if (beetle.y>69.55) {                 beetle.y=69.55;             }             if (beetle.x<898.65) {                 beetle.x=898.65;             }             if (beetle.x>898.65) {                 beetle.x=898.65;             }         }         protected function pressHandler(event:MouseEvent):void {             switch ( event.target ) {                 case up_btn :                     up=true;                     break;                 case down_btn :                     down=true;                     break;                 case left_btn :                     left=true;                     break;                 case right_btn :                     right=true;                     break;             }         }         protected function clickHandler(event:MouseEvent):void {             switch ( event.target ) {                 case up_btn :                     up=false;                     break;                 case down_btn :                     down=false;                     break;                 case left_btn :                     left=false;                     break;                 case right_btn :                     right=false;                     break;                 case toggle_btn :                     mode=! mode;                     break;             }         }         //*************************         // Public methods:         public function go( degree ) {             beetle.y -= speed*Math.cos(beetle.rotation*(Math.PI/180));             beetle.x += speed*Math.sin(beetle.rotation*(Math.PI/180));             if (beetle.rotation<degree) {                 beetle.rotation+=10;             }             if (beetle.rotation>degree) {                 beetle.rotation-=10;             }         }     } } package slideshow{     import flash.display.*;     import flash.events.*;     import flash.net.URLRequest;     import flash.text.*;     import mvc.SlideshowModel;     public class SlideshowDocument extends MovieClip {         public var slideModel:SlideshowModel;         public function SlideshowDocument() {             slideModel = new SlideshowModel();             slideModel.load(new URLRequest("gallery.xml"));         }     } }


and heres how I'm importing it::
ActionScript Code:
import code.Interactivity1; import slideshow.SlideshowDocument; var Interactivity1:Interactivity1 = new TheInteractivity(); var SlideshowDocument:SlideshowDocument = new TheSlideshow();


Any ideas on what I might be doing wrong here?

Thanks!
robmcmon is offline   Reply With Quote
Old 01-14-2010, 05:51 PM   #2
scorpion9
Senior Member
 
Join Date: Feb 2008
Location: Estonia
Posts: 453
Default

are u sure u need to define package two times.
as far as i know u need only one.

and if u are using the classes in the main timeline, and they are in the library then u probably dont need to import them, but im not sure in that.
scorpion9 is offline   Reply With Quote
Old 01-15-2010, 05:11 PM   #3
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,879
Send a message via Skype™ to henke37
Default

Only one class per file.
henke37 is offline   Reply With Quote
Old 01-15-2010, 05:45 PM   #4
the binary
Senior Member
 
the binary's Avatar
 
Join Date: May 2003
Location: berlin | germany
Posts: 960
Default

Quote:
Originally Posted by henke37 View Post
Only one class per file.
exacltly, at least when they are in different packages..
__________________
8bm
the binary is offline   Reply With Quote
Old 01-15-2010, 06:08 PM   #5
3pepe3
;)
 
3pepe3's Avatar
 
Join Date: Aug 2006
Location: In transit--- Still bored
Posts: 1,740
Default

you can have several classes in one file (internal class), ONLY accecible on that file
__________________
http://www.pepemagana.com
3pepe3 is offline   Reply With Quote
Old 01-15-2010, 06:19 PM   #6
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872
Default

Quote:
Originally Posted by 3pepe3 View Post
you can have several classes in one file (internal class), ONLY accecible on that file
Many of us have come across bugs arising when you do this though.

It's allowed by the compiler, but the support for it is kind of shabby, and don't be surprised when buggy things occur as the number of classes inside a file increase.



note: the use of the word 'internal class' and 'package' is kind of vague in this thread.

A class defined after the main class of a .as file is considered internal to a sub package. But it's not internal to the package that the main class is. You can have classes that are internal to normal packages (described by directory tree).

example:

ActionScript Code:
package mypackage {     public class MyClass     {          public function MyClass() {}     } } class MyExampleInternal() {      public function MyExampleInternal() {} }

MyExampleInternal is internal and accessible ONLY to MyClass.

But this does not make it internal to the package 'mypackage'. You can have classes internal to 'mypackage' as well.

ActionScript Code:
package mypackage {     internal class MyInternalClass     {          public function MyInternalClass() {}     } }

this class too is accessible by MyClass... it is also accessible by any other class in the package 'mypackage', but not to anything outside of that package.
__________________
www.lordofduct.com - come read my blog!

If you want to know how to program, take a math class, take a lot of math classes!
lordofduct is offline   Reply With Quote
Old 01-15-2010, 06:26 PM   #7
ASWC
Super Moderator
 
ASWC's Avatar
 
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528
Default

I won't ever go there (multiple classes in one file) at least not with AS3. And I do advise to do the same. As LOD said bugs arise + it actually doesn't bring any relevant advantages according to me. I don't have a problem making an internal class in a package and make this class be used by only one class in the package. Enforcing the relationship by making this internal class part of the target class as is not relevant for me.
__________________
aswebcreations
Super Duper!
ASWC is offline   Reply With Quote
Old 01-15-2010, 07:03 PM   #8
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872
Default

Quote:
Originally Posted by ASWC View Post
I won't ever go there (multiple classes in one file) at least not with AS3. And I do advise to do the same. As LOD said bugs arise + it actually doesn't bring any relevant advantages according to me. I don't have a problem making an internal class in a package and make this class be used by only one class in the package. Enforcing the relationship by making this internal class part of the target class as is not relevant for me.
There is one time I find it 'somewhat' useful.

AS3 lacks a 'struct', so I use these internal classes to define an internal 'psuedo-struct'... or I call them 'clasps'. It can be useful at times in some ways.

Usually though I still prefer to define these in a package instead of internal to a class. But sometimes I do, if it's really not necessary elsewhere and I'm feeling lazy. Really that's where it boils down to... am I being lazy?

Example could be:

ActionScript Code:
class MyClasp {      public var value1:int;      public var value2:String;      public function MyClasp( val1:int, val2:String )      {            value1 = val1;            value2 = val2;      } }

I wish that adobe would include a struct at some point. But they probably won't ever do that until Java includes one as well. So I hope Java does too!
__________________
www.lordofduct.com - come read my blog!

If you want to know how to program, take a math class, take a lot of math classes!
lordofduct is offline   Reply With Quote
Old 01-15-2010, 07:15 PM   #9
ASWC
Super Moderator
 
ASWC's Avatar
 
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528
Default

My Java teacher told me that he was teaching us how to code AND how to be lazy. So I guess you are fine!
__________________
aswebcreations
Super Duper!
ASWC is offline   Reply With Quote
Old 01-15-2010, 09:48 PM   #10
3pepe3
;)
 
3pepe3's Avatar
 
Join Date: Aug 2006
Location: In transit--- Still bored
Posts: 1,740
Default

I don't use internals but i have seen some AS3 files using those kind of structures.
[whispering]
Well today I use an internal just for test porpouse
[/whispering]
@lordofduct, by the way i have been reading some of your classes and nice work
__________________
http://www.pepemagana.com
3pepe3 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:19 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.