I have a library item in my FLA that uses ActionScript Linkage. I'm linking this item to an existing class. When I write the path in the Class input window I can click the pencil icon and open the class in Flash profesional. I export the swc in a swc folder. But in Flash Builder the class that the library item links to wont recognize any named display object instances in the linked library item. And when I compile and test the swf and add the class to the diplay list I see nothing.
But if I just use ActionScript Linkage with the library item and set the Path field so that it puts the linkage Class in the default package, I can create an instances of this linked library item.
So the swc and Flash builder are working, but just not when I link the class to an existing class.
Are you using getDefinitionByName() to obtain a reference to the object? If so I've found if I don't have a reference to an object in the main SWF I cannot find the class either. I ended up having to create a fake reference to each item I wanted in my Main.as which was a growing pain.
public class Main extends Sprite
public function Main()
// useless SWC references
private function _initReferences():void
private function _loadALibraryItem():void
// get a class reference, init via class to the correct type (e.g. Sprite)
var itemClass = getDefinitionByName("SomeLibraryID") as Class;
var item:Sprite = Sprite(new itemClass());
The general idea was Flash Builder did not compile the library items even though they had a class name because there were no references to any of them. Once I made a reference in the Main SWF I could access them in any other class, not just Main.
This is similar to the OS codepage dictating which font outlines are embedded via Flash Pro (Flash Builder can get around this) rather than the built-in font manager. You tell Arial to embed Korean and it simply doesn't, just latin. Sometimes Flash/Builder makes decisions on its own that it really shouldn't, like deciding library items don't exist unless you make a bunch of useless dead references just for the compilers sake. I feel like this is back to c/obj-c with a .h file so I can predefine variables before I define them.....
Thanks for your reply. I think my issue is different. In Flash Builder I am able to reference and instantiate classes from the swc that was created with Flash Pro. But I can't get Flash Builder to recognize a link between an existing class and an ActionScript Linkage class in the swc. In the Flash Pro file I can link the library item to the existing class, I can verify it with the green check box, and I can edit it with the pencil, but in Flash Builder the existing class can't access any of the objects in the Flash Pro swc linkage class.
Are you creating a class and then are applying it as the base class for a library item? It sounds like you're doing this and then when you instantiate the class the library items display objects aren't present.
I'm not using it as a Base Class, I'm using it as the Class. This of course works when working in a Flash Profesional Project in Flash Builder, but I'm working in an ActionScript Project in Flash Builder and I'm using a swc for all my assets but I can't get this feature to work right.
I'm using Flash Builder and Flash Pro. I'm using Flash pro to create a swc for my ActionScript Project in Flash Builder. When I use ActionScript Linkage in the swc and give the class a unique name and have it exported to the default package I can instantiate it in my Flash Builder project. But if I try to attach or link the ActionScript Linkage class in my swc to a specific and existing class in my codebase, Flash Builder instantiates this class from codebase with out any of the art from the swc. So it appears that my Flash Builder ActionScript project is not linking the class in the swc with the class in the codebase.
I've had no such issues so it sounds like Flash Builder has more than one class invading each others namespace.
I do the same. I use Flash Builder 4.6 and I use Flash Pro CS5.5 to create library elements, exported for actionscript with a linkage ID. I export my Flash Pro library to a SWC and import that into Flash Builder. I then have no problems instantiating any library object from the SWC.
I'll just make a quick example. A Flash file containing only a circle (Sprite) in the library with a linkage ID. I'll export to SWC. I'll make a new ActionScript FB project and import the SWC. I'll then instantiate it and add it to the display list and it will show up.
That said, you'll have to be a bit more clear on how this "other" class is loading the SWC. Where is the class located that's loading it? Is it another Flash Pro document with the SWC being loaded and used? How exactly are you loading the SWC into "another class" without loading the SWC into Flash Builder? A class cannot load a SWC.
I too can do as you describe. Like I said, I can instantiate a class from the swc. But I can not link a class in the swc to a class in my code base. This is possible when working with a Flash Professional Project in Flash Builder, but it doesn't work when using an ActionScript Project in Flash Builder.
In the Flash Pro file I can write out the file path in the Class field: "com.package.ClassName". Then if I click the green check box it says that it can fine the class. When I click the pencil icon it will open up the class. But when I export the swc and then in Flash Builder try to instantiate this class it's not linked to the class in the swc.
In your example you are just instantiating a class that is not linked to an external class in your code base. Try linking MyCircle to a class in your code base, and then instantiate it. I'd be interested in what happens.
does that make sense?
I think so. You can redownload the same link:
I made a new AS3 doc in Flash Pro, set the base class to an external file (com.example.Main). I kept the circle in the library. I exported it as a SWC.
I imported that SWC in FB. I instantiated the SWC itself (com.example.Main) as the MovieClip it is. I ran a custom method from the class (HelloWorld()). I also grabbed the circle from the library and put it on the screen as well.
I mentioned namespace above because the com.example.Main is what separates it from the default package so FB can correctly access the right class.
Looking at your FLA you aren't linking MyCircle to an external class. Your example is not attempting to do what I'm trying to do. Try linking MyCircle to an external class that is in the same shared code base as your Flash Builder project.
In the FLA Publish settings set a source path to Flex.src.
Then create a package in the src package called "test".
Then create a class in the test package called MyCircleClass (make sure to extend Sprite or MovieClip)
Then in the FLA link MyCircle to MyCircleClass. So the Class path in the properties panel looks like this: test.MyCircleClass. Not the Base Class path, but the Class path.
Then click the green check box, it should find the class.
Then click the pencil, it too should find the class.
Export a swc.
Then go into ExampleLoadSWC and instantiate MyCircleClass.
When I do this, MyCircleClass would be empty.
Ultimately it's the same concept. A flash document IS a MovieClip so setting its base class is the same. Also as long as your linkage in the library uses the class you share in Flash Builder but has a different class name for the library item itself it will be easy for FB to differentiate.
I moved the com.example.Main into the Flex src folder and changed it to com.example.MyCircle. I made this the base class of the "MyCircle" library element. I changed the library elements class name to RedCircle.
FB can clearly see com.example.MyCircle now as it's in src. I instantiate RedCircle and add to the display list and I see it. I invoke the HelloWorld() method from inside com.example.MyCircle, which is the base class of RedCircle and therefore inherited and you see it traced.
Perhaps, using the example for context, you did something like make the "Class" (not the BASE Class) com.example.MyCircle for the library element. Then when you try to instantiate com.example.MyCircle, of course FB will first look in its own class paths before the SWC to get the class. That's the point of having a Base Class and a Class separately.
Okay we are getting closer. So it sounds like what you are saying is that what I want to do is not possible with a Pure ActionScript project in Flash builder using a swc.
I don't want to use a base class. I want to be able to access objects in the library item. Using a Base class wont work for that.
The method that you are using wont allow for this. I of course can not access any properties in RedCircle from within MyCircle.
When I use a Flash Project in Flash Builder I can link an item in the library to a class in the code base, then in this class I can access all the objects in the library item. This is what I want to do, but can't when using a swc and an ActionScript project in Flash Builder.
I want to have a class in my code base that extends an Abstract Class, then I want a class in the swc to link to this child class. Then I want to be able to access all of the swc class objects while of course inheriting everything from the Abstract Class.
The only way I've gotten this to work is to have the Library item's base class be the Abstract Class, export the swc. Then using my external code base class I extend the swc class, and with this class I can access everything in the swc class and inherent everything from the Abstract Class, but code hinting doesn't work, I get lots of "?". However it exports fine.
I guess this is the only solution?
So in short, it appears that when using an ActionScript Project in Flash builder and a swc, you can not link, or merge, a class in the swc with a class in the code base. Flash Builder defaults to the codebase class and ignores the ActionScript Link in the swc.
But this is possible when using a Flash Project in Flash Builder and no swc.
That sucks : (
Sorry there isn't a better solution but you have to expect issues if you share common classes and tell flash builder to compile using a class directly in its source path. It will always go there first and hit other linked paths, and SWCs later.
I do agree it's an issue, but it's a fair issue. Most of the time people do this is strictly code completion. I wish there was a code completion class path setting..
If that's all you need please mark it as answered and good luck!
They always accept suggestions and one of my favorite things about FlashBuilder and Flash Develop is excellent code completion. Maybe you should suggest a code completion library path setting be added? I'd vote for it if you post a link
Here's the link to the basic suggestion form:
Well, as they say, composition of inheritance. So now I use an interface for my "views" (library linked items). So I have a class that extends the linked library item and implements the interface. And I have a Component View wrapper/manager class that either instantiates this view object or is passed the view object. The component view holds the functionality and listens to the view object. It's probably a better solution anyway. Now I can more easily switch between Flash display list objects and something like Starling.