[SOLVED]Swf select frame


(Gabriele Marchi) #1

Hi guys,I need your help for a doubt i can’t find answer online… i’m working on a preloader, i’ve the percent of progress of download. Can i load an Swf file and advance with frames manually when progress percent is greater than a fixed percent? I can’t found any function to stop/play the swf or to select the frame… It’s possible? Or have I to make a large spritesheet/array of frames?

Thank’s Gabriele


(Jean) #2

Although I can’t help on your main question, but may I suggest you using a cropped image? You know, a progress bar that have lets say 200px, then for every % loaded increase the width of the cropped image 2px. Pretty simple and works well with not very detailed images and don’t requires externals swfs.


(Gabriele Marchi) #3

thank’s for the answer… hum, for what i’ve decided to do i can’t crop an image. There is a character on the top of the loading bar following the progress and continuosly trasforming itself so i need to load a swf or a sequence of frames…


(Zachary Lewis) #4

This thread on Adobe’s forums might help: Access the second frame of the loaded swf


(Gabriele Marchi) #5

Thank you!! exactly what i was looking for!!


(Gabriele Marchi) #6

Here my solution for anybody who have the same problem, i think it can be improved but it works^^

   import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.utils.ByteArray;
import flash.utils.getDefinitionByName;

/**
 * ...
 * @author AuthorName
 */
public class Preloader extends MovieClip
{
	
	private static const FRAMENUM:Number = 120;
 
 [Embed(source = "../assets/Movies/loading.swf", mimeType = "application/octet-stream")] private var PRELOADER_ANIM:Class;
private var mc: MovieClip;
 private var percent:Number = 0;
 private var ldr: Loader = new Loader();
 
    public function Preloader()
    {
        if (stage) {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
        }
       

         ldr.contentLoaderInfo.addEventListener( Event.COMPLETE, onLoad );
		ldr.loadBytes(new PRELOADER_ANIM as ByteArray);
    }

	 public function onLoad( e:Event ):void 
	{
	if( !e.target )
		return;
	mc = e.target.content as MovieClip; 
	addChild(mc);
	
	 addEventListener(Event.ENTER_FRAME, checkFrame);
     loaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);
     loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);

	}
	
    private function ioError(e:IOErrorEvent):void
    {
        trace(e.text);
    }

    private function progress(e:ProgressEvent):void
    {
		
		
		if (mc != null)
		{
        percent = Math.round(e.bytesLoaded / e.bytesTotal * 100);
		mc.gotoAndStop( (int)(percent * FRAMENUM / 100) ); 
		}
    }

    private function checkFrame(e:Event):void
    {
        if (currentFrame == totalFrames)
        {
            stop();
            loadingFinished();
        }
    }

    private function loadingFinished():void
    {
        removeEventListener(Event.ENTER_FRAME, checkFrame);
        loaderInfo.removeEventListener(ProgressEvent.PROGRESS, progress);
        loaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, ioError);
		

        startup();
    }

    private function startup():void
    {
		
        var mainClass:Class = getDefinitionByName("Main") as Class;
        if (parent == stage) stage.addChildAt(new mainClass() as DisplayObject, 0);
        else addChildAt(new mainClass() as DisplayObject, 0);
		parent.removeChild(this);
    }	 

}

Thank you again!^^