Actionscript 3.0 :: Accessing Library Items From Other Classes?
Aug 28, 2009
How do you access Library items from classes other than the document class?For example, if I create a movie clip in Flash and Export it for Actionscript with the name Foo, I can do this in the document class:
Code: Select allvar f = new Foo();
this.addChild(f);
And it appears on the stage, as it should. But I need to be able to create other instances of this object from other classes. If I use the same code above in SomeOtherClass.as, I get nothing on the stage, obviously because this class doesn't know about the Foo object in the library.
I'm using a preloader to load an external SWF then initiating it through its document class using this code:
Code: private function loaderCompleteListener(event : Event) : void { var loaderInfo : LoaderInfo = event.target as LoaderInfo ;
[Code]....
The problem i'm getting is that the Flash that is being loaded has a lot of classes exporting on the first frame, which now cannot be accessed, and therefore I get "The definition of base class cannot be found" errors.
How do I ger the items in the library that export to AS accessible by the parent loading SWF.
I've been working with/around and dodging a situation where I'm trying to access FLA library movieclip assets, but NOT from the document class. I capitalize this because this is my 4th forum posting. I know the answer to that one:
instanceName:ClassName = new ClassName();
The easiest solution for accessing library items from a SubClass looks to be this:
// at topimport TestLocalMC;// in constructorvar box:TestLocalMC = new TestLocalMC();addChild(box);
However, it doesn't show up. I tried a fake non-existent class. It gave me an error so I know it's referencing a Class in the library that I supplied. If I trace the object, it shows up. If I trace the X value, it says 0. So logically, it should be right in front of me..but it's not there! .Am I on the right track? Is this familiar at all to anybody? Is there something I'm missing?
if I could reference FLA library items with a bit of freedom from the document class. Having to go up the hierarchical class tree everytime to retrieve a movieclip is getting rather painful.
I'm slowly working my way through AS3, and have a question about how to do this. In as2, you could just load a swf file, then use attachMovie("itemLibraryLinkageName");. I know in AS3 you have to use addChild() to add items to the display list, but how would you go about adding the library items to the stage from an externally loaded swf in AS3? I've tried:
Code: Select allvar library:MovieClip; var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);[code].......
I've been running circles around this preloader I have for days now. There's a number of problems, but the main one I can't seem to figure out is how to retrieve a library asset from an external class that's not the document class.I have a Preloader_mc class in the library. But the Document.as class doesn't need it really. I only need it once I instance the actually Loading.as class. So I'm trying to access it from the Loading.as and I'm not getting anywhere.I also gave up by instancing it in the Document.as and then referencing it by:
Code: Master.preloader_mc or
Code: Master(root).preloader_mc
Static or not, I just wanted access to the thing for once. Which worked until I had to remove it from the Loading.as. Then it wouldn't budge no matter what I typed.
how to access library items in the main SWF directly from a SubClass by doing this:
package{ import SubClass; public class Main extends MovieClip{public var mySubClass:SubClass = new SubClass;this.addChild(mySubClass); }//class }//package
package{ import Box; public class SubClass extends MovieClip { public function SubClass():void{var train:Box = new Box;this.addChild(box);}//SubClass constructor function }//class }//package
But how do I access library items of a loaded SWF in the same fashion? Importing is different from loading and I'm not sure how or where to piece instances together at runtime.
I am creating a library in AS3. Inside the library I make use of a bunch of classes/packages that need not be exposed to the end user of my lib. I want to only expose one of these classes.
I guess my questions are:
1) How are libraries commonly distributed in AS3?
2) Is there a .jar equivalent in AS3 that developers can include, but will only have access/knowledge of the classes I've declared as public?
This is probably something very simple, but I'm not too sure of the code used to access items within an array.Suppose I have an array like this (using Kirupa's Arrays example):
And we've loaded up the corresponding variables/text for "bananas", thus the current item = bananas.Therefore the next item would be "oranges". How can I tell Flash that I want to access this next item?? (I'd like to be able to access it through a variable so that the same action can be applied when the item is "oranges" to move to the next item, which would now be "apples").
Say I create a symbol, and then another inside the symbol. In the library I now have 2 symbols. Is there a way to combine these into just one library item?
I have a flash file, which is a header for a website. I inherited it from my company's previous webmaster. I was looking through the library items & see alot of images & graphics that I don't see in the finished product on the webpage. The guy worked really sloppy so it's possible there's alot of unused items. Is there anyway to easily tell which items are not used in the final exported flash file so I can clean it up?
Basically, I have a menu created using XML. Each menu item has a fill that fades in and out as the user scrolls over them. What I want to happen is that when an item is clicked, it stays highlighted. The problem comes when I click on the second item. I can't get the first item to "unselect."Here is the menu code and functions.
Code: var menuHolder:MovieClip = new MovieClip(); menuHolder.x = myMask.x;
I downloaded a flash template for my website. All the library items are not local. Here's the path:..........websites20004sources2007dekabr_#lana_2128flashps d1_ikon.png How can I save my library items so I can edit them in FW? I have CS4.
Flash CS4 is really good for design and development point of view. But I noticed two things:If library have more item then there is no option on right click "Select Unused Items". How can I get this option "Select Unused Items" on right Click while library have a more items with scrollbar?Some times the actions window's height increased. At this time there is no option to decrease the height of actions window except the Reset option.
I'm practice with Flash, and trying out different things, but somehow, I managed to create a movie symbol from a graphic symbol, and now whenever I try deleting one of the symbols, it effects the other symbol as well.
I only want one of these symbols, yet I can't seem to only keep one. They both seem to depend on each other, and I don't know how to get around this.
I am developing a site in flash and have over 800 Library Items. My problem is, I need to edit a portion of a Library Item and cannot find the Library Item, and NO, I did not delete the Library Item because when I go to preview or test the flash document, the Library Item is there in the movie. Is there any way to search for the Library Item? I am using Flash Professional 8..
ok so i know the general code to rename all selected library items
var items = fl.getDocumentDOM().library.getSelectedItems(); for (var i=0; i<items.length; i++){ var item = items[i]; item.name = "ABC_"+item.name; }
but this isn't good enough if the library items are in folders... because item.name returns the full path, but item.name sets the name. o.O as someone else points out here, [URL]
so when i try to rename Level1 to be ABC_Level1 if Level1's folder path is LIBRARY/FolderA/FolderB/Level1 i get this instead ABC_FolderA-FolderB-Level1
i could probably code some sort of string parser something like this,
I've got a flash movie that loads images from an external folder. I'd like to make a CD version and would like to have the images embedded in the flash movie so that the images can't be copied from the cd. I thought I could add the images to the Library and reference them from the xml file.
I was wondering if you could loop through your library or a specific folder in your library and get alle linkage names of items that have 'Export for Actionscript' checked. I have an amount of items in my library of which I want to random pick one. Of course I could just use an array of linkage names that correspond to my library items, but I was wondering if there is a more efficient way.
Does flash store the items in the library in an array? I would guess yes. For example if i have an array named pics in my fla file can i write something like:
if there is a way to get a manual text list (or an array or really just anything I could use to get an overview) of items in the library of an FLA...?
I have about 60 movieclips of different flags in my FLA- they all are "linked" to be used in Actionscript- so they have names there but are not named otherwise (as instances on the stage, for example).
Is there a way to get a list of them? I don't want to have to type them all out manually, if there is another way
I'm still in the 'need to learn a lot more' phase of AS3 and am wondering the best way to do this. I have some graphics (MovieClips) in my library that I'd like to have use the same class. But Flash wants unique class names.What's the proper way to handle this? External swf graphics?
lets say you have a whole website written in classes, and you have some items in the library as well (maybe some buttons, a picture for a background and so on...)what to do with all these simbols?leave them in the library, give them all a class name, and when the website loads access them like that, or pull them out on the stage, not neccessarily in the visible area, and not neccessarily on the first keyframe.
so I have a few questions about preloading and specifically preloading in relation to items within the library which get added to the stage through AS3.
The main thing I don't understand is, what is the library? Are these assets contained within the FLA itself and is their data transferred to the SWF on export? If that is the case, does preloading the entire SWF preload its entire library (even the items that are not on the stage?)
If not, how do I preload items which are in the library?
Don't know if I should place this here, but this is where I'm at the most and possibly this needs some coding.I'm working on an Android App and I've been constantly working on getting my content as small as possible, recently I found a way to make it even smaller with remaining quality. But now I have to manually change every file/import a new one and change the movieclips contents. This is A LOT of work, is there some way to batch replace a lot of files at once?
I've got two classes running...one is a document class (EgoGame.as) and another is a class linked to several similar movie clips (Ball.as).I'm trying to access a public variable from Ball.as which has been declared in the doucment class EgoGame.as.When I run the test the outputs states the following...1120: Access of undefined property _ballPlaced.Here's my code. What I'm trying to do is remove the event listeners from the Ball.as when the _ballPlaced variable is true, so that the user can't drag and drop the balls after they've been placed in a zone.
I have a project that i'm working on, and in the project it's important that i have an object that i can create with actionscript that already has two arrays inside of it. To do this, i made the movieclip, i checked export for actionscript in the library, and in the custom class that corresponds to that object i made the arrays with the following code:
package { import flash.display.*; public class cont extends MovieClip {
I've been working my way towards better OOP design lately and I've come across a problem with accessing functions in other classes from my Main class. Here is the code:
They are listening for functions that are within the Player.as class, these functions control the dynamics/movement of the player itelf. But for some reason I'm getting a 1120 error(access of undefined property). Basically how do you listen/access for functions within a different class?
I want to access an object from a class in which it was not created in. I have a main class (A) in which I create and instantiate an object (of class B), from this class I can obviously do whatever I want with the object, no problem. The issue I'm having is another class (C) needs to access the object in question to change its x and y location values. Class C doesn't know what the instance of class B, created in class A, is; this doesn't surprise me, but I can't figure out how to allow class C to get access to what class A created.