Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

is it possible to combine FLA, AS3, and Flex?

Mentor ,
Jul 16, 2013 Jul 16, 2013

Hi.  I have a concept for using assets created in the Flash GUI and stored as Library elements in the Flash GUI but accessed and manipulated via AS3?  The issue I have is the concept has to be developed in Flash Builder/Flex 4.7 so I'm trying to figure out if there's a way to export each FLA library element using some kind of automated process that will enumerate each object for easy scripting access via an AS3 Array or Array Collection in Flex.

Any examples on this?  Thanks in advance.

TOPICS
ActionScript
3.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 16, 2013 Jul 16, 2013

If you need to use objects created in Flash IDE as library in other dev environment - just compile SWC from the FLA that contains these objects and use this SWC as an external library in Flash Builder or any other IDE. As far as enumeration goes - perhaps you can do something with JSFL but it may be too much trouble. If FLA assets have linkage classes - using them is just a mater of instantiation of these classes which is no different from the standard syntax of creating instances.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 16, 2013 Jul 16, 2013

Second thought re enumeration.

You don't need JSFL. Just write a class that will contain an instance of array of library instances --> create SWC --> use instance of the class that has array to read values in Flex.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 16, 2013 Jul 16, 2013

Thanks Andrei.  I'm still somewhat new to Flex and creating an SWC is something I've never compiled before.  At least not knowingly.  I'm also somewhat uncomfortable with classes but I am doing a bunch of reading and tutorials to get caught up.  I have been distracted since I last used to post to the Flash forum with other projects including music.

So hopefully I wlil be able to apply your suggestions.  Thanks for responding.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 16, 2013 Jul 16, 2013

Just to clarify, Andrei.  ..

How would I create enumerated Library objects in the Flash IDE before compililng my SWC without having to manually add them to the library?  Is there a batch command for adding multiple items simultaneously?  I can work with Flash CS4 through Flash CC.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 17, 2013 Jul 17, 2013

You have to add objects to FLA library if you want them to be represented as distinct classes in SWC (or SWF) for outside consumption.

Automations in Flash IDE can be handled via JSFL. I am not the right person to talk about JSFL to because I don't know this stuff.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 17, 2013 Jul 17, 2013

Hi.  Maybe you can help me with this part.  I have successfully added 313 items to the Library and Stage.  I have converted each automatically using JSFL that I found online to a Movie Clip with unique numerical name (begins with the word "Symbol" e.g. Symbol_1_mc and have successfully used the command to convert to Flex component.

I published a SWC with the Publish settings option and now have a file (example name "MyComponents001.swc" and have placed this in a new Flex Project in Flash Builder 4.7 into the libs folder.  However I get an error in the Problems view which says definition libs.MyComponents001.swc could not be found.  I used the import statement in the fx:Script part "import libs.MyComponents001.swc;" without the quotes and then tried to create a for loop to add each element to the canvas automatically. 

I get a blank canvas.

I don't think I'm working with the SWC properly.  Perhaps there is online documentation which can teach me how to do this correctly?  Thanks in advance.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 17, 2013 Jul 17, 2013

This is a bit confusing.

What do you expect to accomplish by the directive "import libs.MyComponents001.swc;"?

Import directive is used to map packages or classes. SWC is neither one. SWC is a library that has (or is supposed to have) packages.

This means that if SWC does not have top level package and all classes are in the same top level - you do not need to use import directive. You will just reference classes directly. For example:

if SWC contains class Symbol_1_mc you will instantiate this class like that:

var symbol1:Symbol_1_mc = new Symbol_1_mc();

This is if symbols in SWC are linked to their corresponding classes.

Other than that it is not possible to help unless there is more info about how classes are structured in the SWC.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 17, 2013 Jul 17, 2013

Hi Andrei,

it is hard to tell how the swc is structured since I can't open it in a text editor.  I will try your suggestion to instantiate the classes directly as the swc was generated from an FLA that just had library elements which were flex components at the top level of the library.  They had their linkages set,, I saw that.  They are simply Movie Clips which have been converted using Flash's command "convert to Flex component"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 19, 2013 Jul 19, 2013

markerline wrote:

Hi Andrei,

it is hard to tell how the swc is structured since I can't open it in a text editor.

You can look and see what Classes are in a swc in Flash Builder when you've added the swc to the build path. Look in the Package Explorer>Referenced Libraries>YourSwc.swc>default package.

swc.PNG

I'd instantiate one of these like:

var sound:Sound = new CF_Ex_01_Sound();

Do you actually need to convert your assets to Flex components? Will they work as just MovieClips or Sprites? Would it work to just specify UIMovieClip as the Base Class for each symbol? What, specifically, are you trying to accomplish?

Message was edited by: Amy Blankenship

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 19, 2013 Jul 19, 2013

Amy, hi. I thank you for taking the time to contribute to this thread.  In the interim I posted here where Andrei1 also responded with simplified code:

http://forums.adobe.com/message/5521006#5521006

Let me see if I can explain my end goal.  In the thread above I created a SWF using Flash CS6 by importing an AI document with Movie Clip instances that, when imported to the stage, come in with unique instance names (w0, w1, w2, etc).  These movie clips are actually Letterforms that have been subdivided into small polygonal pieces that, when combined with audio and some sine wave math will move by rotation and scale dynamically.  I was successful in creating a dynamic SWF in that thread though I have yet to post my updated code which is not as simplified and elegant as Andrei's solution, mind you.

What I am trying to do is integrate this SWF into a Flex application that will load any audio file from the assets folder built into the AIR application OR from the user's local hard drive using the File() method.  I have successfully taken a simple drawing application and added to it the functionality of loading sound so I'm thinking that this loaded sound can access the Movie Clip instance names via a for loop and using the getChildByName method to drive the audio the same way that I have hard-coded the audio loading into the SWF.  I will update my SWF to include a button to begin playback, but a simple SWF does not give me access to the user's file system the way a Flex application can.

In the end I want a user to use this drawing application to draw paths on the stage that will get pushed into an array which will be able to use Sound and Math.sin to drive a dynamic animation.  If I get a chance to develop further I will also code some Tween functions (such as the caurina tweeners that I learned about some time ago) so that I can have even more interesting animation than just rotation and scale.

If I don't need to use Flex components then why has Adobe implemented this functionality as a command in Flash?  How else would I be able to access the instance names of the objects on the stage in Flex/Flash Builder?

If I can use the Movie Clips in the compiled SWF, what is the code to access those Children?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 19, 2013 Jul 19, 2013

A few things:

  1. Flash player 10+ can access the file system.
  2. You can publish to AIR from Flash--you don't need Flex.
  3. The Sound Class doesn't have any functionality for interacting with or recognizing MovieClips AFAIK.
  4. When you export a Flex component, it does not make it any more available for use than just selecting Export for Actionscript and checking Export on Frame N. It just adds support for the Flex component lifecycle and hooks up any labels in the symbol as states.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 19, 2013 Jul 19, 2013

Hi again Amy,

From my research Flash Player is limited in its access of the file system due to security issues.  Yes I know that you can publish AIR from Flash.  You "can" link sound with movie clip animation to make dynamic animation.  I have done it and you can research "audio visualizers" on the web to see examples of how Flash is used to visualize audio.  I am even interested in using MIDI which a few small handful of people have researched and worked with.  It's not the Sound Class it's the SoundChannel that does the lifting.

Can I still see a tutorial on how Flex can be used or do you think I shoud develop everything in native Flash Pro CS6 or CC?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 19, 2013 Jul 19, 2013

I don't really have a ready-made tutorial of using Flash and Flex together--you're right, one is needed and it's on my list. However, any time I have for the next few weeks will be spent honing my 360Stack presentation. In the meantime, there are a couple of things here http://flexdiary.blogspot.com/search/label/workflow that touch on using the two together, but they assume you're already doing it and have run into problems.

I seem to recall that on the digitalprimates site there was a tutorial on how to do TDD with Flash that walks through the steps of how to set up to use a swc from FB. It could also be on Adobe TV, because I think it was a MAX presentation.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 19, 2013 Jul 19, 2013
LATEST

Thanks for the update.  I'll see if I can locate that Max presentation.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 17, 2013 Jul 17, 2013

Here is the code snippet:

public function init():void{

                myMC = new MovieClip();

                for (var i:int=0; i<313;i++){

                   

                    var myMC:Symbol_+i+_mc = new Symbol_+i+_mc;

                    addElement(myMC as IVisualElement);

                   

                    //myArr="Symbol_"+i+"_mc";

                    //addElement(myArr as IVisualElement);

                }

               

            }

I'm not sure if I'm supposed to be casting as IVisualElement or not but code completion tells me that all of the Symbols are there referenced by the SWC.  I just don't know how to create an array from SWC's that are containing 313 different Flex components.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 17, 2013 Jul 17, 2013

This code snippet works, but only on the first movie clip:

import mx.core.IVisualElement;

           

            //import libs.WDVMLayersSequence00102;

           

           

            public var myMC:MovieClip;

            public var myArr:Array;

           

           

            public function init():void{

                myMC = new MovieClip();

                for (var i:int=0; i<313;i++){

                   

                    var myMC:Symbol_1_mc = new Symbol_1_mc;

                    addElement(myMC as IVisualElement);

                   

                    //myArr="Symbol_"+i+"_mc";

                    //addElement(myArr as IVisualElement);

                }

               

            }

of course i am calling the init() function at the creationComplete event in the header of the mxml.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 17, 2013 Jul 17, 2013

Hi again.  This code snippet cleared out any pre-compiler errors

import mx.core.IVisualElement;

            import mx.flash.UIMovieClip;

           

            //import libs.WDVMLayersSequence00102;

           

           

            public var myMC:MovieClip;

            public var myArr:Array;

           

           

            public function init():void{

                myMC = new MovieClip();

                for (var i:int=0; i<313;i++){

                    var myString:String = "Symbol_"+i+"_mc";

                    var myMC:UIMovieClip = new (myString as UIMovieClip);

                    addElement(myMC as IVisualElement);

                   

                    //myArr="Symbol_"+i+"_mc";

                    //addElement(myArr as IVisualElement);

                }

               

            }

but then when I ran the application I got an error 1007 Instantiation attempted on a non-constructor.  How can I pass a concatenated String as a constructor-type?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 18, 2013 Jul 18, 2013

You cannot make compiler aware of data types by using strings (unless there is a gap in my knowledge of course). Only if data type is in the application domain already you can gain reference to it via using dynamic strings.

You have two options:

1. In FLA that ends up as SWC you need to create an object that will enumerate all classes reference in some sort of collection (Array, Vector, etc.). Than, in an application that consumes SWC library, you will need to gain reference to this collection at compilation. Is it possible to automate collection creation with JSFL? I don't know.

2. RSL route. Compile SWF from FLA with entire library included and then load this SWF at runtime into parent application domain. This way you will be able to get datatypes by using getDefinitionByName().

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 18, 2013 Jul 18, 2013

I don't get it.  I have recompiled an SWF and it compiled a SWC for me somehow in Flash.  I have all of my objects on the stage and they are referenced as Flex components when I converted them.  I first created movie clip names in Illustrator then imported the AI file into Flash and the MC's came in just fine.  But they had no AS linkage which was solved by the Run Command convert to Flex component.  Now I found this site and the code doesn't work:

http://www.emanueleferonato.com/2011/03/31/understanding-as3-getdefinitionbyname-for-all-eval-maniac...

I am trying to use getDefinitionByName and I know that the SWC has referenced the movie clips with code completion.

I am not too clear on your two options that you listed as I am still a newbie.  What I was initially trying to do was to create an array of my classes but I did not know the syntax.  And now I am trying to use getDefByName and I don't know the syntax either it seems.

Help!!

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 19, 2013 Jul 19, 2013

getDefinitionByName() is a method that you can use ONLY at runtime. This means that classes that you try to reference must be INSIDE COMPILED swf. getDefinitionByName WILL NOT make these classes to be be baked into swf.

The fact that you see your classes in code completion is just an indication that compiler can see classes in the library but, again, it doesn't mean that these classes will be baked into the final swf. In order for the classesto be compiled with the swf you need to explicitly write references to these classes datatypes. And this is your challenge - gaining references to classes cannot be achieved through converting strings into datatypes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 19, 2013 Jul 19, 2013

Thank you for your insight Andrei.  I guess what I'm saying is that I need an example of how to enumerate the objects that are on my SWF stage or in my SWF library (one or the other but not both) and how to write a Class for that.  Couldn't I use getDefinitionByName on an SWF that loads at runtime?  That way I can still manipulate the objects using Flex?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 17, 2013 Jul 17, 2013

Hi I found this tutorial but I could not make sense of it.  Maybe you can help me along....

http://jansensan.net/loading-assets-dynamically-part-2

Thanks in advance, markerline.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines