I'm trying to use the Flash-Animated-GIF-Library. It serves to load an animated gif. It does it with the fileReference class, where you have to browse your folders, choose an animated gif and then it'll show it on the stage. I need the animated gif to show without that browsing part. Is it in anyway possible to use that class to load animated gifs directly, the same way you'd load and show an image with the Loader class? If so - how?
Yes, you have 2 options.
Use the Loader or URLLoader class. Example1, Example 2 (get bytearray)
Embed the image and get ByteArrayAsset. Example
The minimal code for option1 (Loader):
protected function handleCreationComplete(event:FlexEvent):void
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
loader.load(new URLRequest("yourgif.gif"));
}
private function loaderComplete(event:Event):void
{
var loaderInfo:LoaderInfo = LoaderInfo(event.target);
var byteArray:ByteArray = loaderInfo.bytes;
player.loadBytes(byteArray);
}
The minimal code for option1 (URLLoader):
protected function handleCreationComplete(event:FlexEvent):void
{
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, loaderComplete);
loader.load(new URLRequest("yourgif.gif"))
}
private function loaderComplete(event:Event):void
{
player.loadBytes(event.target.data);
}
And for option2:
[Embed(source="yourgif.gif",mimeType="application/octet-stream")]
public var YourGif:Class;
protected function handleCreationComplete(event:FlexEvent):void
{
var byteArrayAsset:ByteArrayAsset = new YourGif();
player.loadBytes(byteArrayAsset);
// should work, too
//player.loadBytes(new YourGif() as ByteArray);
}
Related
I am Writing code to load image From Server With a Timer Function Of 2 seconds . I want to know the Size of Each image . Is it Possible to Know in ActionScript 3.0?
enter code here
public class Example extends Sprite {
public function Example() {
var myTimer:Timer = new Timer(2000);
myTimer.addEventListener(TimerEvent.TIMER,runMany);
myTimer.start();
function runMany(e:TimerEvent):void {
var loader:Loader=new Loader();
var url:String= "http:/google.com.example3";
loader.load(new URLRequest(url));
addChild(loader);
}
}
}
}
You can use the contentLoaderInfo.bytesTotal property of the Loader class.
trace(loader.contentLoaderInfo.bytesTotal);
Or you can add an event handler:
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
function progressHandler(event:ProgressEvent):void
{
trace(event.bytesTotal);
}
I made a small change on the above code
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
function progressHandler(event:ProgressEvent):void
{
trace(event.bytesLoaded);
}
Instead of bytestotal. I put bytesloaded. It works and shows the loading.
I'm loading a background image via the Loader() class and wanted to know if there's a way to create a sprite from that loaded image?
I'm wanting to put a function in an external class file to put the image in the loader and then call the class to create a sprite from the loaded image. I'm not even sure this is possible.
Note: I'm using flashdevelop and no timeline.
You can just use the loader object as a display object or you can access the Bitmap object in the loader and add that to a sprite.
var loader:Loader = new Loader();
loader.load(new URLRequest(filename));
addChild(loader);
loader.x = 100;
loader.y = 200;
//so on
To get access to the bitmap and bitmapdata loaded just add an event listener and access them.
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest(filename));
private function onLoadComplete(e:Event):void
{
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
var loadedBitmap:Bitmap = loaderInfo.content as Bitmap;
var sprite:Sprite = new Sprite();
sprite.addChild(loadedBitmap);
addChild(sprite);
sprite.x = 100;
sprite.y = 200;
//so on
}
I get error with load image into swf file. Here is my code:
private var loader:Loader = new Loader( );
public function Battle()
{
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("http://www.google.com.vn/images/srpr/logo4w.png"));
}
private function onComplete(event:Event):void
{
addChild(loader);
}
e very thing is OK, logo of Google appeared. But I need to manipulate pixel the image have loaded. I add a image Bitmap :
private var loader:Loader = new Loader( );
private var image:Bitmap;
public function Battle()
{
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("http://www.google.com.vn/images/srpr/logo4w.png"));
}
private function onComplete(event:Event):void
{
image = Bitmap(loader.content);
this.addChild(image);
}
There is nothing appear. I can't find any solution on internet. I try and detect :
private function onComplete(event:Event):void
{
image = Bitmap(loader.content);
//after above line, rest of function never run
addChild(image); // <-- no run ##
trace("this no run"); // <-- no run ##
}
I use Flash Builder 4 and have no error or any warning.
Can somebody show me a solution, please?
Thank for reading.
You can't access pixel data of an image if image is in different domain than your application (and there is no crossdomain policy file)
1 You need crossdomain.xml on Google site :)
2 You need use checkpolicy:
var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("http://www.google.com.vn/images/srpr/logo4w.png"), context);
but it works only if Google add crossdomain.
3 You can use little serverside proxy on your domain. Flash call proxy to get file with your url, proxy download it and return to flash...
I'm trying to link pages together by using swf. I originally used scenes but I heard swf r better so I need help. I have the swf loading but the main menu won't go away. I tried using alpha=0; but it's no good.
code:
vid1_btn.addEventListener(MouseEvent.CLICK, nextPage);
//Create a function for the button click
function nextPage(ev:MouseEvent):void
{
var request:URLRequest = new URLRequest("page1.swf");
var loader:Loader = new Loader()
loader.load(request);
addChild(loader);
//this.background_mc.alpha = 0;
}
You can try
addChildAt(loader, 0);
if your menu is only chlid there.
Or you can set this loader downword by
loader.y = 100;
if your menu is on top of the screen.
First, your code should be somewhat like this:
function nextPage(ev:MouseEvent):void
{
var request:URLRequest = new URLRequest("page1.swf");
var loader:Loader = new Loader()
loader.load(request);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
//this.background_mc.alpha = 0;
}
function swfLoaded(e:Event){
addChild(e.target.content); /* or e.target, i'm not sure*/
}
hi need to instantiate document class in as3. I have a main movie which will load load.swf. The document class of load.swf is LoadedMovie. i use this code :
public function Main()
{
var url:URLRequest = new URLRequest("load.swf");
loader=new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
loader.load(url);
}
function finishLoading(e:Event)
{
var sn:LoadedMovie=new LoadedMovie();
addChild(sn);
}
it's added the movieclip and but my framescripts were not working. i have stop at last frame.
Is it any other way to do this.
The Loader will contain an instance of your loaded swf's document class once it's loaded. Simply addChild the loader and you're in business.
var url:URLRequest = new URLRequest("load.swf");
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
loader.load(url);
addChild(loader);
Instanciating from a loaded swf is slightly more complicated, you have to deal with application domains and such.