Skip navigation
Currently Being Moderated

ActionScript Linkage in a swc - linking to an existing class not working right

Aug 15, 2012 8:44 PM

Hi,

 

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.

 

Any suggestions?

 

cheers.

 
Replies
  • Currently Being Moderated
    Aug 16, 2012 6:53 AM   in reply to DJ Gecko

    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.

     

    e.g.

     

    package

    {

              import flash.display.Sprite;

              import flash.utils.getDefinitionByName;

     

              public class Main extends Sprite

              {

                   public function Main()

                   {

                        // useless SWC references

                        _initReferences();

     

                        _loadALibraryItem();

                   }

     

                   private function _initReferences():void

                   {

                             var a:SomeLibraryID;

                             var b:SomeOtherLibraryID;

                             var c:YouGetTheIdea;

                   }

     

                   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());

                        addChild(item);

                   }

     

              }

     

    }

     

    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.....

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2012 10:19 AM   in reply to DJ Gecko

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2012 10:57 AM   in reply to DJ Gecko

    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.

     

    Example Flash Pro SWC w/ FB Project loading library element.

     

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2012 11:37 AM   in reply to DJ Gecko

    I think so. You can redownload the same link:

     

    Example Files

     

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2012 12:30 PM   in reply to DJ Gecko

    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.

     

    Example File

     

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2012 1:12 PM   in reply to DJ Gecko

    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!

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 17, 2012 6:01 AM   in reply to DJ Gecko

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 17, 2012 12:31 PM   in reply to DJ Gecko

    Here's the link to the basic suggestion form:

     

    https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

     
    |
    Mark as:
  • Currently Being Moderated
    May 13, 2013 12:00 PM   in reply to DJ Gecko

    Hi DJ,

     

    Did you ever come across a better solution for this?

     
    |
    Mark as:
  • Currently Being Moderated
    May 13, 2013 12:22 PM   in reply to DJ Gecko

    Thank you for the speedy response!

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points