ActionScript 3.0 :: Flash Getting MovieClip From Library In Class
Jun 22, 2010
I am working on a flash game that I am building in Flash Builder 4. I have a library of movieclips in the FLA file and need to create instances of these movieclips within objects of a custom class. I am unsure how to refer to the library of the flash file while in a class file.
I also would like to call these movieclips dynamically based on the combination of two strings. I know it is possible to create variables dynamically with this[variableName]. Can I refer to library objects from the flash doc in the same way?
View 4 Replies
Similar Posts:
Jun 7, 2009
Running Flash CS3, I've reviewed the lynda.com tutorial on building particle systems in ActionScript 3.0 to try and build some shooting sparks in an animation.I'm getting stuck at what I think is a really elementary point, but I can't seem to get past it.
Basically, all I'm trying to do at this point is create a class called Particle (which I will teach to do things that particles do a little later) link it to a MovieClip on the stage in my .fla file and use the particle's update function to move it across the stage in a manner defined in the instance (so I can later give different movement properties to each AS generated instance of the MC). I know there are easier ways to accomplish my base task without loading an external package, but this seems so strightforward that I must be doing something very simple wrong I just can't see so I thought I'd post the code here and see what I'm missing.
I start with a file called Particle.as in the same folder as my Spark Test.fla file.
In Particle.as I have the following code:
package{ import flash.display.*; public class Particle extends MovieClip { public xVelocity:Number; public yVelocity:Number; public function Particle() { xVelocity = 0; yVelocity = 0; } public function update():void { this.x += xVelocity; this.y += yVelocity; } }}
So I'm declaring that all particles are built with no motion, but if they are explicitly granted an x or y velocity, they will move by that much when the instance's update function is called in the timeline.
Then in my Spark Test.fla file, I have a small shape in a MovieClip called Spark. In the Linkage properties of Spark I have chosen to Export for ActionScript and Export in FIrst Frame. The class is called Spark and the Base class is Particle. For testing purposes I've dropped an instance on the stage and called it spark. Then in the actions layer in the first frame (the timeline is just the spark layer and the actions layer, one frame long each with no "stop();" so it should run forever) I have included the following code:
spark.xVelocity = 5;spark.yVelocity = -1;
function updateSpark(event:Event):void{ spark.update();}
addEventListener(Event.ENTER_FRAME, updateSpark);
What it looks like this should do is on each ENTER_FRAME Flash should call updateSpark which is a function that runs the update() event for the spark instance which is a instance of a movieclip that has an update event which moves x and y position by their relative velocity variables. This all seems pretty straightforward to me, but when I ctrl-Enter to test the movie, I get the following 3 compiler errors:
Particle.as Line 1: 5000: The class 'Particle' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
Particle.as Line 7: 1071: Syntax error: expected a definition keyword (such as function) after attribute public, not xVelocity.
Particle.as Line 7: 1084: Syntax error: expecting rightbrace before semicolon.
View 7 Replies
Sep 17, 2010
how to add a MovieClip from the library by a class i've MovieClip and i want to add it to the stage by a class note i've already a class and linked to a MovieClip and what i woona do is to addChild another MovieClip in the stage
View 3 Replies
Aug 3, 2009
I create a dot as a movieclip in the library. also i set the linkage to Dot class. Is it OK to create an external class Dot to associate with the movieclp inside the library? if it's ok. I would like to ask that is there any wrong in my code?
Code:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Dot extends MovieClip {
[Code]....
View 6 Replies
Sep 17, 2009
I just want to ask if is it possible to load a movieclip from the library using the Loader class together with the URLRequest and then use gotoAndPlay method?
View 1 Replies
Aug 26, 2009
Is it even possible to associate a class file to a movieClip manually placed on the stage without setting up the class linkage in the library? If so, how?
P.S. linking in the library then placing on the stage is not a viable option. Nor is using "addChild" from the library.
View 9 Replies
Nov 9, 2009
I have a movieclip library symbol exported for ActionScript with name McFloor and identifier McFloor and I'd like to access it from OneChart class.
[Code]...
View 1 Replies
Dec 11, 2010
I've created a simple class that defines a scrollbar to scroll content. I've applied this class (ScrollBox.as) to a movieclip in the library as the Base Class.
Now, I'd like to add this movieclip to the stage with AS3. So for the Linkage, I've given the movieclip a class name of 'AboutBox'. This is the code I've written to add it to the display list[code]...
View 5 Replies
Apr 19, 2009
I have a MovieClip in the library with a class associated with it. I can instanciate the MovieClip just fine using code and add it to the stage without any problems. But how can I manually add the MovieClip to the stage and feed it the one parameter when it's instanciated? I've tried all the usual stuff but nothing seems to work:
var testClip:className = new className("helloworld");
testClip is the name of the MovieClip that's been manually placed on the stage.
View 4 Replies
Dec 10, 2010
I've created a simple class that defines a scrollbar to scroll content.I've applied this class (ScrollBox.as) to a movieclip in the library as the Base Class.Now, I'd like to add this movieclip to the stage with AS3.So for the Linkage, I've given the movieclip a class name of 'AboutBox'.This is the code I've written to add it to the display list:[code]
View 1 Replies
Jan 18, 2011
Okay, so I decided to try putting some child movieclip switches into the .as instead of in the frames. After a lot of Googling and reading, I think I learned that each of those movieclips need to be in their own .as. Anyway, I tried to do it and the movieclip, which is located in the .fla library and does have export checked off, is not showing up when I play the file. The movieclip has this .as to itself:
[Code]...
View 4 Replies
Jun 10, 2010
I am making a Thumbnail class which is part of my Photo Gallery Package that I am building with the intent of automatically generating my thumbnails. I do not want to limit myself to just AS3 animations, I would also like the ability to use timeline animations. I have a system using "in" and "out" for frame labels which I find very efficient and I get stuff done quickly. So I created the thumbnails holder MovieClip with the animations and have it linked in my Library, however, when I try to pass it to my Thumbnail Class, I only get one instance and I need to create several instances.
Document Class
ActionScript Code:
var thumbCont:mcThumb = new mcThumb();
thumbNails = new Thumbnails(thumbCont);
Thumbnails Class
ActionScript Code:
var thumbContainer:MovieClip;
public function Thumbnails(thumbCont:MovieClip,) {
thumbContainer = thumbCont;
}private function createThumbs():void {
for (var i:int = 0; i < aThumbs.length; i++) {
[Code] .....
I eliminated most of the additional stuff. What this does is that it doesn't create several thumbContainers, rather it just uses the one. So how would I be able to generate several of them? I can obviously create an Array with them and create them in my document class, but if I can avoid that and have my thumbnail class do it by itself, that would be perfect.
View 2 Replies
May 10, 2005
How do I reference a library movieclip in a class? I couldn't get it to work entering the name of the class in the linkage properties (as2 class name text field). The variable was undefined. I know I'm missing something....what is it?
View 4 Replies
Aug 20, 2006
Is there a way to extend the movieclip class without using a library item and attachMovie?
View 3 Replies
Jul 17, 2004
can you declare multiple classes and then register each movieclip from the library to a different class? It isnt working for me.I created two different classes and created two entire different movieClips and registered each movie clips to a different class.However, I can only use on movieClip at a time, when I use the duplicateMovieClip... command to create copies of the movieclip, i find that only those movieclips, whose class i declared first, appear on stage.
View 1 Replies
Mar 13, 2011
I'm trying to load a RSL library into a flash animation developed with Flash CS5 IDE, that extends a custom class and implements an interface. I have reduced the problem to the simplest setup and find that I can have my main class extend another class or implement an interface, but not do both at the same time if I want to load an RSL.I have a very simple class to extend:
import flash.display.Sprite;
public class MySprite extends Sprite
{[ code]...........
but if I want both I get the VerifyError: Error #1014 with MySprite not found and ReferenceError: Error #1065.
View 2 Replies
Jun 20, 2010
I'm creating a mask effect. i create 10 movieclip with a library class reference that appear on the screen with a random alpha effect. THe problem is that if i try the effect alone all works ok. if i mask the layer that contains the effect on an image i don't see the effect. i see directly the image masked with the boxes. i can't explain that because i've the effect first but it seems that when i test the movie the effect doesn't play and the boxes appear directly on the screen.
View 5 Replies
Aug 26, 2011
So I know you can assign a base class to a library definition within the Movieclips library information field but If I have 30 items in the library and I change the Base class this becomes a pain in the ass, can this be done programmatically when I instantiate the library definition?
var new_shiz:MyItem1 = new MyItem1(); // Needs to have a generic base class of MyItem
View 2 Replies
Feb 15, 2010
I have a movie clip that holds one bitmap image, some simple AS3 to change the image displayed, and a ton of bitmaps I've imported into my library.Currently, I swap the images by changing the bitmapData
holder.bitmapData = new test2(1,1);
but this requires me to check off 'Export for ActionScript' in every symbol. I'd rather not go through every bitmap in the library and do this, is there some way to reference them by their library name?
View 1 Replies
Jul 11, 2009
I've seen that it's very simple to create a document class (a class associated to the main timeline itself), or an instance of a class which is linked to a single asset (e.g. a movie clip).But what if I need to implement a class (let's call it Main) which uses multiple assets from the Flash library? The only way I know to do this is by instantiating any asset with its linked class, and passing them all to the Main constructor like this:
ActionScript Code:
var asset1:Asset1 = new Asset1(...);
var asset2:Asset2 = new Asset2(...);
var asset3:Asset3 = new Asset3(...);
[code].....
This is kind of a tedious process, especially when the composition hierarchy is long and you have to pass them all as arguments through many nested classes.For instance, I needed to link a preload sprite (the typical circle in gradient color which is constantly rotating until the load is complete) from the library to any thumbnail class of a gallery, which in turn is part of another class, which in turn is part of the main class. So I needed to pass this preload clip as an argument throughout the nested classes.
View 8 Replies
Mar 24, 2009
I have a symbol in the Library with a Base Class that extends the MovieClip Class and adds some additional functionality. I want to be able to export this from the Library by right clicking on the symbol and selecting Export SWF. I was hopping this would essentially give me the same results as if the symbol contents was on the main timeline and I had declared the Base Class as the Document Class. When I import this SWF using the Loader Class it seems to loose all of Base Class functionality and think of itself as a MovieClip.
Looking at the below sample code, the alpha property is correctly set but the param1 getter is unaccessible. What the hell is going on?
[Code]...
View 1 Replies
Oct 14, 2010
I created an flv video player using Flash Builder 4. This "BasicVideoPlayer" project is compiled into a SWC that will be eventually be used to create other video players that extend the functionality. One of the features is a view that appears when the video has finished playing that displays a "Play Again" button. This "Play Again" view has its own class, "BasicPlayAgain", that accepts a graphic asset that is exported from a .fla file that contains all of the graphic/UI assets.
In my new project, "EnhancedVideoPlayer", I'm using the BasicVideoPlayer SWC as a library to create a new video player that will add more functionality to the "Play Again" view; specifically it will add more buttons to that view.The EnhancedVideoPlayer uses a default class that extends the BasicVideoPlayer class. The BasicVideoPlayer class has a member called "playAgainScreen" whose type is BasicPlayAgain. The EnhancedVideoPlayer needs to override the playAgain member and recast it as EnhancedPlayAgain so it can control the new buttons properly.
View 1 Replies
Jan 22, 2011
The use of library classes confuses me once again. I have the following situation:
[Code]....
I cannot put in any baseclass when using the class, so I'm forced to remove the baseclass. When using only the class I get a whole bunch of errors don't make any sense at all, and still appear even if I comment out all the code in the Page class. comop_padpagesFavorietenPage.as:7: 1152: A conflict exists with inherited definition com.op_pad.pages:Page.help in namespace public.
[Code]...
View 1 Replies
Jan 18, 2012
i have a flash file with a number of movieclips in the library - various bubbles that can be popped at a clilck. The fla has a document class - BubbleGame.as, and the various bubble mcies in the library are all exported for action script, (using their own names, but) with a mutual Base Class - BubbleBase.as, in order that all the various bubble movie clips have the same behavior: load in a random position, play out their own timelines, be popped when clicked, and if not popped - reload in another position.
This is all working very well, however, I want the movie clips removed if they hit an object on the stage. The object has an instance name of sym_mc, and I have tried various bits of code to cause the bubble to be removed when it hits that object, but i either get errors or nada.
I tried doing the hitTestObject code in both the document class and the base class. It seems more appropriate to have it in the base class - BubbleBase.as (below), because that tells the bubbles what to do.
[Code]...
View 12 Replies
Feb 9, 2009
determine the base class of a Flash library object at runtime, using Actionscript? The toString method gives me the class of the object, but what I'd really like to determine is the superclass of the object. So, if I have an Actionscript class called "Fruit" and I created many different Fruit types in the Flash library ("Cherry", "Apple", etc.), is there a way in code I can determine that an "Apple" is a child of "Fruit"?
View 2 Replies
Dec 9, 2010
Library symbol "Card" is linked to class "Card" which extends "MovieClip". Library symbol "Card" contains a card background image.Library symbol "Ace" is linked to class "Ace", which extends class "Card". Library symbol "Ace" contains a TextField with a big letter "A".So we have Ace extends Card which extends MovieClip. Ace therefore extends MovieClip, but does not DIRECTLY extend MovieClip.When I drop an instance of Ace on the stage and compile the clip, all that shows up is the big letter A. However, I expected the background image from Card to be included, since Ace extends Card, and the Card symbol contains the background.It seems like Flash ignores symbol content unless it belongs to the top-level class being instantiated.I think it's LAME that one symbol can't extend another. The IDE could easily draw Card as a non-editable background while I'm editing Ace which extends it, and it should instantiate Card's content and then Ace's content when an Ace is instantiated.
View 3 Replies
Nov 15, 2011
Why does Flash still offer to declare library items as either MovieClip, Graphic or Button? Is this just for backwards compatibility or is there any reason not to use MovieClip for everything? (Well, Button does have some additional functionality, but what about Graphic? does a Graphic have any advantage over a MovieClip?)
View 1 Replies
Jun 24, 2009
And i cant figure it out.the "my.fla.class"content looks like this
Code:
package my_fla
{
[code].....
View 2 Replies
Aug 19, 2010
I have a symbol named picHolder. In symbol properties under linkage, I chose "Export for ActionScript" and "Export in frame 1" and gave it a class name of picHolder.Normally, to instantiate a new instance, I'd say:
Code:
var tempPic:picHolder = new picHolder();
and I'd go about my way.
[code].....
View 1 Replies
Aug 13, 2010
I am new to AS 3.0 and getting stuck with few things.I want to add movieClip named "button" to stage from library.Linkage to custom class name "customButton".Now,
View 1 Replies