-
inheritance
Hi i am learnig opps...
Actionscript Code:
package { import flash.display.MovieClip; import flash.events.Event;
public class Cir extends MovieClip { public function Cir() { this.addEventListener(Event.ENTER_FRAME, mov, false, 0, true); } private function mov(evt:Event):void { this.x += 5; } } }
the above is external action script file named "Cir.as".
In the fla file i have a moviclip on stage and have the class name "Cir". Both fla and *.as files are in same location. As i mentioned in the as file the circle moving 5 px. But if i relocate the *.as file inside any folder named "com", its is not working....
i put the script in timeline " import com.Cir;
But still it is not working... Why... Pls help me guys...
-
This is in com folder:
Cir.as
Actionscript Code:
package com{ import flash.display.MovieClip; import flash.events.Event;
public class Cir extends MovieClip { public function Cir() { this.addEventListener(Event.ENTER_FRAME,mov,false,0,true); } private function mov(evt:Event):void { //this.x+= 5; // Both of this will work; evt.target.x+= 5; // This is more into OOP. } } }
This is outside of the com folder:
FLA Timeline Code.
Actionscript Code:
import com.Cir; var c:Cir=new Cir(); addChild(c);
The Class Name of the Symbol in the Library is : com.Cir --> This is targeting the Cir.as Class which is inside the com folder.
Test Your Movie.
package com
{
}
This mean the Cir.as Class is in com Package. A Folder is a Package in AS3.
arkitx
Last edited by arkitx; 10-02-2011 at 11:08 AM.
-
Edit: arkitx answered faster than I did. So use his/her code.
Are you making your own company?
Replace
with
After package, you have to write the folders the AS is contained in. For example, if you Cir.as is located inside animals\mammals\dogs\chihuahua, then your first line would be:
Actionscript Code:
package animals.mammals.dogs.chihuahua
-
Think you might find this useful:
Actionscript Code:
package com{ import flash.display.MovieClip; import flash.events.Event;
public class Init {
public function Init() { } public static function moveX(obj:MovieClip,speed:int):void { var timeLine=obj.stage.getChildAt(0); var object=timeLine.getChildByName(obj.name); object.speedX=speed; object.addEventListener(Event.ENTER_FRAME,moveObjX); } private static function moveObjX(evt:Event):void { evt.currentTarget.x+=evt.target.speedX; } public static function moveY(obj:MovieClip,speed:int):void { var timeLine=obj.stage.getChildAt(0); var object=timeLine.getChildByName(obj.name); object.speedY=speed; object.addEventListener(Event.ENTER_FRAME,moveObjY); } private static function moveObjY(evt:Event):void { evt.currentTarget.y+=evt.target.speedY; } } }
Flash TimeLine
Actionscript Code:
//-------------------------------------------// import com.Init; //-------------------------------------------// var b:box=new box(); addChild(b); Init.moveX(b,3); Init.moveY(b,1); b=new box(); addChild(b); Init.moveX(b,1); Init.moveY(b,3); //-------------------------------------------// var r:rec=new rec(); addChild(r); r.y=300; Init.moveX(r,2); Init.moveY(r,-1); r=new rec(); addChild(r); r.y=30; Init.moveX(r,2); Init.moveY(r,1); //-------------------------------------------//
Object box and rec are the two MovieClip in Library with a Class Name box and rec
arkitx
Last edited by arkitx; 10-03-2011 at 09:16 AM.
-
Originally Posted by arkitx
This is in com folder:
Cir.as
Actionscript Code:
package com{ import flash.display.MovieClip; import flash.events.Event;
public class Cir extends MovieClip { public function Cir() { this.addEventListener(Event.ENTER_FRAME,mov,false,0,true); } private function mov(evt:Event):void { //this.x+= 5; // Both of this will work; evt.target.x+= 5; // This is more into OOP. } } }
This is outside of the com folder:
FLA Timeline Code.
Actionscript Code:
import com.Cir; var c:Cir=new Cir(); addChild(c);
The Class Name of the Symbol in the Library is : com.Cir --> This is targeting the Cir.as Class which is inside the com folder.
Test Your Movie.
package com
{
}
This mean the Cir.as Class is in com Package. A Folder is a Package in AS3.
arkitx
Thank you, Earlier i tried this. No response... Then i change the path (com.Cir) in the Symbol class property panel. Now its working....
-
Welcome
Did you test my Post #4?
I think it is more useful to make a utility class for most of your common behavior.
arkitx
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|