Ultrashock Forums > Flash > ActionScript
[AS3] use mc on stage via class file

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
[AS3] use mc on stage via class file
Old 2007-10-31

Hi.
Is it possible to use a movieclip I have on stage via an external class file?
I have this class file:
ActionScript Code:
  1. package {
  2.    
  3.     import flash.events.Event;
  4.     import flash.display.MovieClip;
  5.     import flash.display.DisplayObject;
  6.     import flash.display.Sprite;
  7.    
  8.     public class FirkantMove extends MovieClip{
  9.    
  10.         private var speed:Number = 5;
  11.         private var currentDegrees:Number = 0;
  12.         private var circle_width:Number = 300;
  13.         private var circle_height:Number = 50;
  14.         private var myCircle:MovieClip = new MovieClip();
  15.        
  16.         //CONSTRUCTOR
  17.         public function FirkantMove():void{
  18.             addChild(myCircle);
  19.             addEventListener(Event.ENTER_FRAME, movingCode);
  20.             trace("**********addListener is running");
  21.         }
  22.        
  23.        
  24.        
  25.         function movingCode(event:Event):void{
  26.             currentDegrees = currentDegrees + speed;
  27.             var radians:Number = currentDegrees * Math.PI / 180;
  28.             var posX:Number = Math.sin(radians) * circle_width;
  29.             var posY:Number = Math.cos(radians) * circle_height;
  30.            
  31.             Circle.x = posX;
  32.             Circle.y = posY;
  33.            
  34.             trace(posX);
  35.         }
  36.     }
  37. }

Then I have a mc on stage with the instance name "circle" - the mc has a linkage name "Circle".
When I run it I see the posX coordinates in the output window but how can I put these coordinates on the mc I have on stage?
- Michael Brydeboel
http://www.x-itin.dk
postbit arrow 8 comments | 316 views postbit arrow Reply: with Quote   
Registered User
x-itin is offline
seperator
Posts: 86
2005-02-18
Age: 22
seperator

Ultrashock Member Comments:
x-itin x-itin is offline 2007-10-31 #2 Old  
No one can help me?
Reply With Quote  
souichi's Avatar souichi souichi is offline souichi lives in United States 2007-10-31 #3 Old  
You can't access a movie clip directly on stage, but you can import it from the library at run time by attaching it to an empty movie clip created in your class.
Reply With Quote  
x-itin x-itin is offline 2007-10-31 #4 Old  
Okay, what if I want to use a motion tween in the timeline on the movieclip I attach to an empty movie clip?
Reply With Quote  
sentinels sentinels is offline sentinels lives in United States 2007-10-31 #5 Old  
you would need to pass the reference of your MovieClip when you instantiate your class.
Reply With Quote  
x-itin x-itin is offline 2007-10-31 #6 Old  
do you have a link or something to a example, it would be great
Reply With Quote  
sentinels sentinels is offline sentinels lives in United States 2007-10-31 #7 Old  
it all really depends on where you're instantiating your class, unless that's the document class?
Reply With Quote  
x-itin x-itin is offline 2007-10-31 #8 Old  
I instantiate my class by using this code:
ActionScript Code:
  1. import FirkantMove;
  2. var firMove:FirkantMove = new FirkantMove();
If I use the Document Class then I have directly access to the stage, is that true?
Reply With Quote  
sentinels sentinels is offline sentinels lives in United States 2007-10-31 #9 Old  
yes, but if your movieclip isn't instantiated via code, i *believe* you'll have to use getChildByName and not explicitly declare the instance in your class... there was a thread on here awhile back that touched on this very topic. i believe senocular can answer this.
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: