I have the image path manipulate from database with php. Now how can i have to import those image in the library so that i can use them as a symbol. Thanks in advance.
You cannot load it into library, but you can load this image via php and use it on stage with action script. Take a look at this answer to the similar question:
Load image dynamicly in flash
You can download it to the server and generate source file with Class that have field like this:
class Library
{
[Embed(source = 'path_to_folder/image_name.png')] public static var imageClass : Class;
}
Alsou you should refer this class somewhere to be sure it will be compiled into your swf and use it like this:
const image:Bitmap = new (Library.imageClass)();
In that case you need to recompile your swf every time the image is changed.
But I'm totaly agree with Bartek that it is better to use dynamic loading.
Related
I have a client that is requesting an area be built on the stage of an existing .fla file (that I built as well) that loads html content from an external file. This area will serve as a dynamic ad banner that displays the contents of the external file. Ideally, the external file would contain links to different .html files that can easily be edited as the content needs change.
I have tried HTMLloader, but I am limited to a .swf file only and cannot use AIR.
Any thoughts on the best way to do this?
Thanks in advance!
If you are in fact needing to pull content from an external .html file, the following code showcases how to load external html content. In my example, I stored some content in a file named 'MyBannerAd.html', but you can point it to wherever you want and whatever filename you wish. Once the file has loaded, the externalFileLoadComplete function is called at which time I created a textfield and stored the contents of the file that was loaded from the external file as the htmlText property of the TextField. If you already have a textfield created, you can simply reference that one instead. The code shown below executed successfully using Flash CC 2014.
import flash.text.TextField;
function externalFileLoadComplete(e:Event):void
{
var myTextField:TextField = new TextField();
myTextField.htmlText = e.target.data;
addChild(myTextField);
}
var fileLoader:URLLoader = new URLLoader();
var fileRequest:URLRequest = new URLRequest("MyBannerAd.html");
fileLoader.addEventListener(Event.COMPLETE, externalFileLoadComplete);
fileLoader.load(fileRequest);
I would like to embedd a font with AS3 using the "swf method".
The error I get is:
Font "myFont" could not be created
../assets/swf/myFont.swf cannot be transcoded.
As per Google this problem is because of a path-error.
But I think I set the right path, didn't I?
My folder structure
main.fla
../com
..../subfolder
....../testButton
......../testButton.as
....../assets
......../swf
........../myFont.swf
in my testButton.as I'm trying to embedd the myFont.swf:
public class testButton extends Sprite {
[Embed(source="../assets/swf/myFont.swf", fontName="myFont",
fontWeight='bold', mimeType="application/x-font")]
private var myEmbeddedFont:Class;
In the main.fla I'm creating an object of the class.
Just convert the original font file into a .otf and install it. Flash will detect it and you'll be able to use it like a normal font without the embedding.
In the past, there was a simple trick, to include the flex mxmlc module by adding the following line to the flash-cs4 makefile:
-include-libraries “/absolute/path/to/my/assets/assets.swc”
This gave you the ability to use getDefinitionByName, an helper function to access the embedded swc asset-library (instead of creating hand-written classes all assets).
Unfortunately, this has stopped working since flash-cs4. Does anybody know another solution?
Unfortunately, the only workaround I have found is to explicitly refer each of asset classes somewhere in the code. You may create dummy class like this:
public class AssetsExporter extends Sprite
{
public static function export()
{
AssetClass1;
AssetClass2;
//etc
trace( "DEBUG AssetsExporter.export()" );
}
}
Specify this class as Document class in Flash IDE, so it will be compiled into the resulting swc. Then in the main code of your application call
AssetsExporter.export();
After doing this you will be able to use getDefinitionByName().
You can add them to the libraries in the publish settings.
(Image from http://wiki.gigya.com/ via Google Images)
By the way, if you use SWC files, you can also do
new somepackage.SomeClass();
instead of
new getDefinitionByName("somepackage.SomeClass")
where applicable. This is because SWC files are included at compile time, not runtime.
Even though you can change a compiler setting manually, its easy if you are using FlashDevelop as this is very simple to fix.
Right click your included swc from the Project list. Choose options then "include library (complete library)".
..you can now use getDefinitionByName to get an unreferenced class from your swc file.
I have a main.swf which loads a module.swf and the module.swf loads some assets.
The module.swf works standalone and also needs to work when loaded by main.swf.
But unfortunately the module.swf can't find the assets when loaded by main.swf because the assets aren't located relative to the main.swf, but are located relative to the module.swf.
As I can't touch the module.swf and I'm also unwilling to change the directory structure, I am looking for a solution close to the a "base" parameter which can be used when a swf is embedded into html.
Is there a way to simulate the base parameter's behaviour when loading a swf file using Loader?
Here is a similar yet unanswered question.
You could use symlinks as a way to redirect your assets url when loaded via the main swf
Something like this
public class URLUtil
{
public static function getBaseURL(swfURL:String):String
{
return swfURL.substr(0, swfURL.lastIndexOf("/") + 1);
}
}
example of usage inside module:
var assetURL:String = URLUtils.getBaseURL(root.loaderInfo.url) + "asset.filename";
loader.load(new URLRequest(assetURL));
In ActionScript, you can do something like this:
[Embed(source = "src/myfile.xml", mimeType = "application/octet-stream")]
private var xml : Class;
and it will embed your file to be used in code. How can i do something similar in Haxe?
Things have changed since the time the question was asked. With a modern version of haxe one can do:
#:bitmap("test.png") class TestBMD extends BitmapData {}
var bm = new Bitmap(new TestBMD(100,100));
Haxe allows you to provide external resources info for embedding in hxml.
You may refer to the doc.
If specifying width/height annoys you, and if you don't mind not using the #:bitmap metatag, you could do:
import openfl.Assets;
...
var bm = new Bitmap(Assets.getBitmapData("test.png"));
XML is easy to use haxe to get. Add -resource myfile.xml#myxml. Then, in your code, to get the xml string, use haxe.Resource.getString("myxml"). You can then parse this string to xml.