Load MovieClip inline in TextField - actionscript-3

I want to load a MovieClip inside a TextField inline with the text.
The TextField documentation says "HTML text that you assign to a text field can contain embedded media (movie clips, SWF files, GIF files, PNG files, and JPEG files)."
How can this be done with MovieClips? There must be a listener we can override.
source: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/text/TextField.html

From the documentation :
src: Specifies the URL to an image or
SWF file, or the linkage identifier
for a movie clip symbol in the
library. This attribute is required;
all other attributes are optional.
External files (JPEG, GIF, PNG, and
SWF files) do not show until they are
downloaded completely.
You can add MovieClip by setting his linkage identifier in the src attribute of the <img> node.

You can use the <img> tag to link to an swf.
Or, if you need to have more control, place an <img>to load a placeholder, and use getImageReference to access and/or modify the image's Loader object. This will also allow you to set the loader content to visible = false, and add a MovieClip to it using addChild.

For sure MoveiClip can be imported into the TextField inline of your texts...
But there's an easier way also possible from now on, not only the easier way but also more efficient and powerful.
Check out www.doitflash.com
The site produced a class named "TextArea" which is an extension to the original "TextField" class that ends to the shortcomings of TextField.
TextArea not only allows to have MovieClips and SWF files in line of your texts but also allows and created the most efficient ways to communicate with your SWF file live at any time, it allows to have different HTML tags rather than just having the tag to import images, you can have video player, talking avatar, flash buttons and anything else with their own tags to even set their settings dynamically right from your dynamic content.
It has lots of more features and doesn't specifically limited to this issue. Check out doitflash for more information. the site provides the platform and downloading it is also free of charge :)

no you cannot do this in flash. you can only load images in a textfield.

Related

Can Flash text and images be changed without modifying source FLA?

Generally speaking, let's say I create a small, simple FLA animation that simply takes the text "Take a look at Tuesday's Deals!" and moves it across the screen. I then build and generate the SWF file.
Is it somehow possible to create this FLA file so that, once the SFW is built, I can change the text without having to open the FLA and recreating the SWF?
Can it be done with images? For example, I create a FLA with a 50x50px image that moves across the screen. Can I switch to another 50x50px image without having to rebuild the SWF?
The reason I ask is because I can create the initial FLA, but I won't be able to modify. The person that will deal with modifying the text and/or image doesn't know Flash.
Thanks.
Yes, you can load content dynamically at run-time. The design of your application should be such that it loads an xml file or something of that nature to specify what artwork/text to use.
So you need to load an XML file , or some other type of data.
Then dynamically load audio/artwork based on that data.
You can even make the app so that it can load other .swf files with new content.
You can use command line assembler/disassembler to do this. Here are the two command line assembler/disassembler I know.
http://www.nowrap.de/flasm
http://swfmill.org/
Disassemble the swf using either one of this, you will get text file.
In your case you can define a variable for text and find and replace the text.
And finally assemble it a swf.
Hope this helps.
you can pass parameters to the swf containing information to be used.
http://www.mysite.com/banner/banner.swf?text="my text"&image="image1"
var flashVars:Object = this.root.loaderInfo.parameters;
var text:String = flashVars["text"];
var imagetype:String = flashVars["image"];
In the code you treat the data to be received.

Single-swf preloader wrapper in Flash

I have a .swf that I'd like to create a preloader for. In the end, I want a single file which combines both the preloader and the content .swf.
Every tutorial I can find on Flash preloaders offers one of two options:
Using a URLRequest in the preloader wrapper to load an external content .swf. This will not work because I do not want two .swfs.
A "single-swf" solution like this one which works for assets which you have created in the Flash IDE. I assumed I would easily be able to go this route, but I'm having trouble. I cannot use the Flash IDE to import my content .swf. I can use an embed tag like so:
[Embed(source="content.swf")]
private var MyContent:Class;
But it seems like this embedded content is exported on the first frame, so my preloader only appears after the content .swf is loaded. I'm guessing it's something along these lines. Any thoughts?
But it seems like this embedded content is exported on the first frame
You are absolutely correct, all Ebmed do embedding in the first frame by default but mxmlc provides solution by creating two frames swf with preloader in the first frame via the metatag:
[Frame(factoryClass="Preloader")]
You can find step by step guide here http://www.bit-101.com/blog/?p=946.

FlashBuilder: how to embed graphics for preloader?

I develop a project in FlashBuilder. The graphics and UI elements i create in the Flash IDE and give them Export Classnames. then I put the SWC in the library paths of the FlashBuilder project and create the UI elements by instanciation.
Now I want to add a Preloader for the application. I follow this article, which works:
http://pixelpaton.com/?p=4642
My question is now: I also need some graphics for the preloader. But how do I ensure that the graphics for the preloader will be loaded first, such that the preloader class can start as soon as possible?
The compiler will figure out the dependencies for your preloader class, and load them first.
For example:
public function Preloader()
{
addChild(new UIElementFromFlash());
}
Flash Builder will know UIElementFromFlash needs to be loaded before Preloader. It will also load Preloader before your main class and its dependencies as long as you have the Frame metadata tag from the article.
I'd suggest to make 2 swf files if it's possible. Make a loader.swf which loads your application swf and displays the progress and your loading animation/graphics.
See an example here: http://www.republicofcode.com/tutorials/flash/as3preloader/
Then you'll have to add URLLoader class and load your application.swf.
Try looking here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html
Like Gio suggested, having two SWF files is the best practice.
However, one other solution is to use the -frame two argument of the Flex compiler. All your definitions (code and assets) will be added to the second frame of the movie, allowing your main class to listen for the loading progress of the application and display animations.
Be careful to not reference anything from the main application in your first frame, to prevent adding more weight to it.
More detail on this technique here:
http://www.andymoore.ca/2009/08/flexsdk-3-3-how-to-make-a-flash-preloader-in-as3/

Is it possible to extract the symbol out of swf file which was downloaded using URLLoader (and not embedded))

I am trying to download a heavy swf dynamically to my site using URLLoader class. I'd like to know if it is possible to use a symbol inside the swf as a separate object?
The code used right now uses the embed statement as follows:
[Embed(source="/Fight.swf", symbol="Kungfu")]
public class Kungfu extends MovieClip
{ ... }
Embedding the swf increases the initial load time of my site and I want to make it dynamic. How can I access the Kungfu symbol from Fight.swf after it is downloaded using the URLLoader class?
You need to get the class definition from the loaded SWF. Few months ago I summarized the process here. The example used bitmaps, but you can use movie clips as well.
... Why not use SwfLoader? It's Flex native. If you're not in Flex, why not use a Loader?
Either way, I don't think that URLLoader is what you really want here.

When a SWF is loaded into another. Can the main SWF read the loaded one to retrieve its contents and modify them?

Give this scenario:
I have a cool graphic in Illustrator or Flash.
The graphic represents a figure, with various elements inside, shapes, lines, gradients, etc.
I export it to a swf file and I can view my nice graphic if I open it.
I have a (pure) as3 application, which loads swfs.
Then...
Can I manipulate the contents of the loaded swf. For example: Moving its contents, changing some elements inside, duplicating them. Deforming them with the transform matrix and things like that?
Can I, at least, read the contents and replicate them (the graphic data) inside the main application.
As far as I've been researching, I can only import the swf and use it as a whole display object, without any children, and I cannot modify it.
I want to, somehow, use the graphic information of the external swf to allow the main application deform it or use it to make new versions of the graphic.
No, sadly you can't retrieve or change compiled Graphics elements in detail, you can only use them as DisplayObjects and transform them through their public properties (scale, rotation, transform, etc...).
There is way of programmaticaly retrieve a single path coordinates by setting it as the "guide" of an object in the Flash IDE and within an onEnterFrame retrieve the object's position, but as you can imagine, its quite dirty.
You can replicate the clips by either setting them as classes within the loaded SWF (In Flash IDE: library>symbol>properties>export for AS) or using BitmapData to draw them as you please from the main movie.
Another solution would be to use a more open format, like SVG or FXG, but it can get quite complicated...
You can access loaded SWF's methods and properties if both are AVM2 movies.
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
private function onLoadComplete(e:Event):void
{
var content:Object = LoaderInfo(e.target).content;
//assuming there is a public someMethod() defined in
//the document class of the loaded SWF, you can call it as:
content.someMethod();
//you can access any property you wish
content.someObject.graphics.beginFill(0x00ff00);
content.someObject.graphics.drawCircle(10, 10, 10);
content.someObject.graphics.endFill();
}
SWF content can be readed by new function added to Flash Player 11.6 and AIR 3.6:
flash.display.Grapics.readGraphicsData()
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html#readGraphicsData%28%29
Similar problem:
How to read data from shape/graphics object