School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,363 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,431 people online right now. Registration is fast and FREE... Join Now!




How would this be done in AS3?

 

How would this be done in AS3?

Ryan1

14 Jun, 2009 - 08:35 AM
Post #1

New D.I.C Head
*

Joined: 29 Sep, 2007
Posts: 13


My Contributions
How would you use a MovieClip that's in the library in a document class?

Thanks

User is offlineProfile CardPM
+Quote Post


UnknownFury

RE: How Would This Be Done In AS3?

14 Jun, 2009 - 09:02 AM
Post #2

New D.I.C Head
*

Joined: 9 Mar, 2009
Posts: 14



Thanked: 4 times
My Contributions
QUOTE(Ryan1 @ 14 Jun, 2009 - 08:35 AM) *

How would you use a MovieClip that's in the library in a document class?

Thanks


Right click the MC in the library and click linkage. You can then give it a class name. If that class exists (has to extend the MovieClip class) already (i.e defined in an AS file) then that class will take on the image of the MC, if not then a new class will be created. You can then refer to it as you would any other class:

CODE
var myMC:libraryMC = new libraryMC();



User is offlineProfile CardPM
+Quote Post

Ryan1

RE: How Would This Be Done In AS3?

20 Jun, 2009 - 08:32 AM
Post #3

New D.I.C Head
*

Joined: 29 Sep, 2007
Posts: 13


My Contributions
QUOTE(UnknownFury @ 14 Jun, 2009 - 09:02 AM) *


Right click the MC in the library and click linkage. You can then give it a class name. If that class exists (has to extend the MovieClip class) already (i.e defined in an AS file) then that class will take on the image of the MC, if not then a new class will be created. You can then refer to it as you would any other class:

CODE
var myMC:libraryMC = new libraryMC();



I guess I sort of understand this, but it's still not quite working right. I just let it make a new class, named Ball, and referred to it in the code. It adds the MC to the stage at the point 100, 100, but it doesn't allow the x-value to change. Here's the code I'm trying to use;

CODE
package {
    import flash.display.MovieClip;

    import flash.events.Event;

    public class Movement extends MovieClip {
        private var ball:MovieClip;

        public function Movement() {
            init();
        }
        private function init():void {
            var ball:Ball = new Ball;
            addChild(ball);
            ball.x = 100;
            ball.y = 100;
            addEventListener(Event.ENTER_FRAME,EnterFrame);
        }

        private function EnterFrame(event:Event):void {
            ball.x += 5;
        }
    }
}


I end up getting this; TypeError: Error #1009: Cannot access a property or method of a null object reference. at Movement/EnterFrame()

Sorry to be a burden, but learning AS3 isn't working out too good for me.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 08:36PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month