ProgressEvent AS3
In AS2, i can import a MovieClip from library using the
attachMovie, and in this MovieClip i can use the MovieClipLoader
Class to load a image and show the progress (using a MovieClip that
is inside the MovieClip imported). Example:
var mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
var mc:MovieClip = _root.attachMovie("myMc", "myMc"+i,
_root.getNextHighestDepth());
mcl.loadClip("image"+i, mc.holder);
mvl.addListener(mclListener);
mclListener.onLoadProgress = function(target_mc, loadedBytes,
totalBytes) {
target_mc._parent.bar._yscale = loadedBytes/totalBytes*100;
Where, holder is a MovieClip that is in the MovieClip myMc
and bar is a MovieClip that is in the MovieClip myMc. With this,
for each MovieClip that is imported i can show the load progress.
Now in AS3 i am not obtaining the progress from this images,
i even can't say to Flash where is the target to scale. I am using
this:
var loader:Loader = new Loader();
var mc:MovieClip = new myMc();
addChild(mc);
mc.holder.addChild(loader);
loader.load(new URLRequest("image"+i));
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,
loadProgress);
function loadProgress(evt:ProgressEvent) {
var loaded:Number = evt.bytesLoaded;
var total:Number = evt.bytesTotal;
mc.bar.width = loaded/total;
The Flash don´t show the progress from the image and
apears errors on the Output panel. Somebody already passed for this
problem of migration and have a soluction?
Sorry for my english.
Thanks
Hey man, thanks for the answer, but i think you doesn't
understand.
I can't in the funcion loadProgress access the MovieClip bar
that is in the MovieClip myMc that is imported from my library.
Diferent from AS2 where i can access the target from the functon
onLoadProgress now in AS3 i can't do this. And the error that
appears is this: "Access of undefined property mc"
Thanks
[ ]s
Similar Messages
-
Hello,
I'm sending images from a server, in C-berkeley sockets, to a Flash client, both on the same Linux machine:
Average size of each package: 35000 bytes.
Flash requests an image, and the server sends it.
Server spends 30 ms to get,compress and send the image.
OpenCV is used to grab each frame from a webcam.
On Flash, first frames are received in time, every 60 ms but then the elapsed time between two reception events (ProgressEvent.SOCKET_DATA is 170 ms. So it displays images with a low frame rate.
The visualization is not smooth but blurred.
Anyway, the server never waits more than 40 ms to get a client's request, this is what I measure at least..., so is either Flash or server "lying" to me?
If I connect the same Flash to a "as3-server" (OpenKinect server which gets images from the Microsoft's Kinect), everything is OK.
Maybe there is some issue on the server side but I'm using a dedicated one with the classical functions (bind, accept, read, write and close). Any thoughts?
Regards.I'm experiencing the same issue.
I'm sending images from a C# server to an AS3 client.
Everything is fine, with a transfert time of around 30ms per image.
Then, for no apparent reason images take 300 or 600 or more time to get to the client.
Then, after even some more time, it fixes itself and goes back to 30ms.
- When everything is fine, SOCKET_DATA events contain about 24820 bytes each. (images themselves are 1 to 8MB).
- When the problem occurs, SOCKET_DATA events contain 65636 bytes each, with occasionally lower values.
- It is only some SOCKET_DATA events that takes long to be called back, generally one or two per image sent.
I have series like this:
(normal)
socket.bytesAvailable: 24820 bytes. Inactive for 0ms.
socket.bytesAvailable: 24820 bytes. Inactive for 0ms.
socket.bytesAvailable: 24820 bytes. Inactive for 0ms.
(slow)
socket.bytesAvailable: 65536 bytes. Inactive for 0ms.
socket.bytesAvailable: 25996 bytes. Inactive for 0ms.
socket.bytesAvailable: 6944 bytes. Inactive for 297ms.
socket.bytesAvailable: 65536 bytes. Inactive for 0ms.
socket.bytesAvailable: 65536 bytes. Inactive for 0ms.
socket.bytesAvailable: 11104 bytes. Inactive for 0ms.
socket.bytesAvailable: 6944 bytes. Inactive for 273ms.
socket.bytesAvailable: 65536 bytes. Inactive for 0ms.
Where "Inactive" is the ammount of time spent between SOCKET_DATA callbacks, outside of my code.
Some packets just take super long to be reconstructed into the byte array and sent to me in the socket data event.
It looks like this happen after a buffer underflow.
I have verified that this behavior is not due to Flash rendering (same problem if I don't display the images or don't do anything else).
Currently my only viable workaround is to detect these long transferts and force a disconnection and reconnection.
Anyone has experienced this and found a better solution or explanation ? -
AS3: How to access and control embedded sounds in an external swf?
I rarely use sounds in AS3/Flash. I am using Flash Pro CS6, but I can't seem to figure out how to access, control (play, stop, etc) sounds embedded in an external SWF loaded into the main SWF.
It's easy to control them when embedded on the main swf. However, on an externally loaded SWR, I get all kinds of errors. For this app, I really need to embed them in the external SWF.
I read several solutions, but none seem to work.
I embed the sound an mp3 file called soundSegment1.mp3 using Flash CS6 import tool and then open the actionscript properties panel on flash to select the class name: SoundSegment1. Then I edit the class code and create a file called SoundSegment1.as and it's saved right next to my document class main.as in the same directory. The code of the SoundSegment1 class looks like this:
package {
import flash.media.*;
public class SoundSegment1 extends Sound
public function SoundSegment1 ()
// no code in here
public function playSound()
var soundSegment1:Sound = new SoundSegment1();
var channel:SoundChannel = soundSegment1.play();
Then, in my main.as, I have done several attempts to play this sound such as:
var fileLocation:URLRequest = new URLRequest(SWFToLoad); loader.load(fileLocation); loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeListener); loader.contentLoaderInfo.addEventListener(Event.INIT, initListener);
function initListener(e:Event):void // I also placed this code on the completeListener and it didn't work { loader.content.soundSegment1.playSound(); // doesn't work. }
I get:
Line XXX 1061: Call to a possibly undefined method playSound through a reference with static type flash.display:DisplayObject.
or, I also read that I should be able to do something like this anywhere in the Main.as file:
var theClass:Class = Class(loader.content.getDefinitionByName("SoundSegment1")); var theSound:theClass = new theClass(); theSound.play() //doesn't work either.
I also tried on the completeListener:
var TheClass:Class = e.target.applicationDomain.getDefinition("SoundSegment1") as Class; var theSound:TheClass = new TheClass();
theSound.play() //doesn't work either.
I get:
ReferenceError: Error #1065: Variable SoundSegment1 is not defined. at flash.system::ApplicationDomain/getDefinition()
I am stuck and I really need to get this to work. I would be genuinely grateful for your help.
Thank you in advance for any help provided. I really need to get it to work, because I can't simply embed them in the main SWF or load them individually externally one by one.
Thanks again!THANK YOU!
I think your code may be over my head though. I think you are using an anonymous function which is not something I am familiar with (but I want to learn about if it's useful).
I also don't know where the classS came from. I see that it's a parameter sent along with the event, but I don't really see where that came from.
Someone at: http://www.kirupa.com/forum/showthread.php?305098-Playing-a-embedded-sound-in-an-external- swf&p=2658098#post2658098
Is showing what seems to be an easier solution, but my problem there is I can't access the source file of the "child" swf.... ayayay.....
I am going to tinker with your solution and see if it gets me anywhere. Thanks so much for your help again. -
Strange problem with ProgressEvent.PROGRESS in different laptob
i made simple of my project to show the problem
the code
package
import flash.display.MovieClip;
import flash.net.FileReference;
import flash.net.FileFilter;
import flash.events.MouseEvent;
import flash.events.*;
import flash.net.URLRequest;
import flash.net.FileReferenceList;
import flash.net.URLVariables;
import flash.net.URLRequestMethod;
public class Control extends MovieClip
public var allTypes:Array;
public var imageTypes:FileFilter;
public var textTypes:FileFilter;
public var fileRef:FileReference;
public var request:URLRequest;
public function Control()
imageTypes = new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
textTypes = new FileFilter("Text Files (*.txt, *.rtf)", "*.txt; *.rtf");
allTypes = new Array(imageTypes, textTypes);
upload_icon.addEventListener( MouseEvent.CLICK, upload_icon_click);
add_icon.addEventListener( MouseEvent.CLICK, add_icon_click);
function add_icon_click (e:MouseEvent):void
fileRef = new FileReference();
fileRef.addEventListener(Event.SELECT, selectHandler);
fileRef.addEventListener(Event.COMPLETE, completeHandler);
fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler);
fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,uploadCompleteDataHandler);
try
var success:Boolean = fileRef.browse();
catch (error:Error)
trace("Unable to browse for files.");
function uploadCompleteDataHandler(event:DataEvent):void {
//result = ExternalInterface.call("error_file_upload", "uploadCompleteData: " + event.data);
trace("uploadCompleteData: " + event.data);
function selectHandler(event:Event):void
testout.text=testout.text+fileRef.name+"==="+fileRef.size+"==="+fileRef.type+"\n";
trace(fileRef.name+"==="+fileRef.size+"==="+fileRef.type+"\n");
function upload_icon_click (e:MouseEvent):void
request = new URLRequest("http://egyouth.com/mahmoud/test/upload.php");
var valebal:URLVariables = new URLVariables();
valebal.login_send_info = 4;
valebal.user = 'mahmoud';
request.method = URLRequestMethod.POST;
request.data = valebal;
try
fileRef.upload(request);
catch (error:Error)
trace("Unable to upload file.");
function completeHandler(event:Event):void
trace("trace");
function progressHandler(event:ProgressEvent):void
testout.text=testout.text+fileRef.name+"==="+fileRef.size+"==="+fileRef.type+"=="+event.bytesLoaded+"==="+event.bytesTotal+"\n";
trace(fileRef.name+"==="+fileRef.size+"==="+fileRef.type+"=="+event.bytesLoaded+"==="+event.bytesTotal+"\n");
this code you can test on
http://egyouth.com/mahmoud/test/mahmoud.html
the problem is when i try this code in my computer progressHandler function work very good
like if i upload 5mb it take like 1m and every 1sec he run progressHandler function
but when i run this code in deferent computer use the same speed ( same network)
i upload 5mb and progressHandler function run very fast and just take 2 secand and tell me the file upload
but the file not upload and after 1 m i will see it in the upload folder
http://egyouth.com/mahmoud/test/files/
so what the problem now ( i think in the secand computer the as3 thought that he upload use the speed of computer not the speed of the network like my laptob )
just for trace my laptob run with adobe flash player 10.0.2.54
and
the second computer run with adobe flash player 10.0.45.2in the second computer run with adobe flash player 10.0.45.2 progressHandler function run very fast ex
when i upload a 100mb it must take 30min but it just take 4 sec !! and it tell me the upload done
but when i open the folder of upload i didnt see the file
and if i still open the page of upload i will see the folder after 30min
i think that progressHandler function in this computer use the speed of computer not the speed of network -
Hi,
I am trying to implement a simple image gallery with alpha transition using as3. But an issue is occuring with this. After each image alpha transition, the stage becomes blank. The code i have used for image Gallery is following.CAn anybody help me. I am trying this for a week. but still i have a hope for make this working. So please help me.
import flash.display.Loader;
import flash.display.*;
import gs.TweenLite;
const TIMER_DELAY = 2000;
var totImages:Number;
var index:Number = 0;
var imgArr:Array = new Array();
var currentContainer:MovieClip = holder0;
currentContainer.alpha = 0;
var transTimer:Timer = new Timer(TIMER_DELAY);
//transTimer.addEventListener(TimerEvent.TIMER, startTransition);
var imgLoader:Loader = new Loader();
var myXML:XML = new XML();
var XML_URL:String = "images.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void{
myXML = XML(myLoader.data);
processXML(myXML);
function processXML(xml){
totImages = xml.children().length();
for(var i=0;i<totImages;i++){
var tempVar = xml..item[i]..image;
imgArr.push(tempVar);
//transTimer.start();
currentContainer = holder0;
loadImage();
function loadImage(){
var url = imgArr[index];
//ImgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressStatus);
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, fadeInImg);
var fileRequest:URLRequest = new URLRequest(url);
imgLoader.load(fileRequest);
currentContainer.addChild(imgLoader);
function fadeInImg(e:Event){
TweenLite.to(currentContainer,3,{alpha:1,delay:2,onComplete:switchClip});
function switchClip(){
if(index < totImages){
index++;
} else {
index = 0;
if(currentContainer == holder0){
currentContainer = holder1;
} else {
currentContainer = holder0;
currentContainer.alpha = 0;
MovieClip(this.root).swapChildren(holder0, holder1);
loadImage();
Thanks and Regards,
SreelashHi Adrei, I have implemented the thumbnail button also. Its working but the problem is that thumbnail buttons and controls are placing behind the image container. How can i place the thumbnail buttons and control buttons over the image. You can view the result in the following url:
http://www.creative-showcase.co.uk/BirdStudiosOld/Videos/test/scrllGallAnd.html
The working swf is with the following url:
http://www.creative-showcase.co.uk/BirdStudiosOld/Videos/test/scrllGall.html
The code that i used for creating thumbnail is following
import flash.display.DisplayObject;
import flash.display.*;
import flash.display.Loader;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.text.*;
import flash.net.*;
import flash.utils.Timer;
import gs.TweenLite;
import gs.easing.*;
var xmlURL:String = "http://www.creative-showcase.co.uk/BirdStudiosOld/Videos/test1/images.xml";
var loadedImages:Array = [];
var imageURLs:Array = [];
var thumbArr:Array = [];
var imageLoader:Loader;
var prevImage:DisplayObject;
var currentImage:DisplayObject;
var thumbContainer:MovieClip;
var currThumb:MovieClip;
var prevThumb:MovieClip = null;
var showTimer:Timer;
var timerDuration:int = 5000;
var tweenDuration:int = 2;
var currentIndex:int = 0;
var activIndx:Number = 0;
var slidesHolder:Sprite;
var prvFlag:Boolean = false;
var nxtFlag:Boolean = false;
var twnFlag:Boolean = false;
var rt_lt_Flag:Boolean = true;
var myXMLURL:URLRequest = new URLRequest(xmlURL);
var xmlLoader:URLLoader = new URLLoader(myXMLURL);
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
xmlLoader.load(myXMLURL);
var a:int = 90;
ctrlBox.btnPlay.buttonMode = true;
ctrlBox.nextImg.buttonMode = true;
ctrlBox.prevBtn.buttonMode = true;
ctrlBox.btnPause.buttonMode = true;
ctrlBox.btnPlay.visible = false;
ctrlBox.btnPause.addEventListener(MouseEvent.CLICK,stopScroll);
ctrlBox.btnPlay.addEventListener(MouseEvent.CLICK,startScroll);
ctrlBox.nextImg.addEventListener(MouseEvent.CLICK,shwNext);
ctrlBox.prevBtn.addEventListener(MouseEvent.CLICK,shwPrev);
function xmlLoaded(e:Event):void {
var a:int = 45;
e.target.removeEventListener(Event.COMPLETE, xmlLoaded);
processXML(XML(e.target.data));
function processXML(xml:XML):void {
var len:int = xml.children().length();
var tempVar:String;
for (var i:int = 0; i < len; i++) {
tempVar = "http://www.creative-showcase.co.uk/BirdStudiosOld/Videos/test1/" + xml..item[i]..image;
//trace(tempVar)
imageURLs.push(tempVar);
preload();
createThumbs();
function createThumbs():void{
thumbContainer = new MovieClip();
addChild(thumbContainer);
for(var i:int=0;i<9;i++){
var thmbHolder:MovieClip = new MovieClip();
thumbContainer.addChild(thmbHolder);
//MovieClip(this.root).swapChildren(currentImage, ctrlBox);
thmbHolder.buttonMode = true;
var thmb:thumbClass = new thumbClass();
thmbHolder.addChild(thmb);
thumbArr.push(thmbHolder);
thmbHolder.name = i.toString();
thmb.imgNum.text = (i+1).toString();
thmbHolder.addEventListener(MouseEvent.CLICK,showImage)
//trace(thmb.imgNum.text)
thmbHolder.x = i*(thmbHolder.width+5)+5;
thumbContainer.y = stage.stageHeight - thumbContainer.height;
function showImage(e:MouseEvent):void{
var imgIndx:Number = e.target.parent.parent.name;
prevThumb = currThumb;
currThumb = e.target.parent.parent;
currThumb.buttonMode = false;
if(activIndx != imgIndx){
prevThumb.buttonMode = true;
currentIndex = imgIndx-1;
shwNext(null);
activIndx = imgIndx;
} else {
stopScroll(null);
function preload():void{
var len:int = imageURLs.length;
for (var i:int = 0; i < len; i++) {
imageLoader = new Loader();
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onPreloadComplete);
loadedImages.push(imageLoader);
imageLoader.load(new URLRequest(imageURLs[i]));
function onPreloadComplete(e:Event):void {
e.target.removeEventListener(Event.COMPLETE, onPreloadComplete);
if (!showTimer && loadedImages[0].content && loadedImages[1].content ) startShow();
function startShow():void{
currentImage = loadedImages[0];
currentImage.alpha = 0;
slidesHolder = new Sprite();
var slideMask:Sprite = new Sprite();
var gr:Graphics = slideMask.graphics;
gr.beginFill(0xff0000);
gr.drawRect(0, 0, currentImage.width, currentImage.height);
gr.endFill();
addChild(slidesHolder);
addChild(slideMask);
slidesHolder.x = slideMask.x = 0;
slidesHolder.y = slideMask.y = 0;
slidesHolder.mask = slideMask;
slidesHolder.addChild(currentImage);
TweenLite.to(currentImage, 10, { alpha: 1 } );
showTimer = new Timer(timerDuration);
showTimer.addEventListener(TimerEvent.TIMER, slideTransition);
showTimer.start();
function slideTransition(e:TimerEvent):void{
var nextImage:int;
if(rt_lt_Flag == true){
if(nxtFlag == true){
showTimer.stop();
nxtFlag = false;
nextImage = currentIndex < loadedImages.length - 1 ? currentIndex + 1 : 0;
if (loadedImages[nextImage].content) {
currentIndex = nextImage;
loadedImages[currentIndex].x = slidesHolder.width;
slidesHolder.addChildAt(loadedImages[currentIndex], slidesHolder.getChildIndex(currentImage));
prevImage = currentImage;
currentImage = loadedImages[currentIndex];
showCurrent();
} else {
if(prvFlag == true){
showTimer.stop();
prvFlag = false;
nextImage = currentIndex > 0 ? currentIndex - 1 : loadedImages.length - 1;
if (loadedImages[nextImage].content) {
currentIndex = nextImage;
loadedImages[currentIndex].x = -(stage.stageWidth);
slidesHolder.addChildAt(loadedImages[currentIndex], slidesHolder.getChildIndex(currentImage));
prevImage = currentImage;
currentImage = loadedImages[currentIndex];
showCurrent();
activIndx = currentIndex;
//trace(currentIndex)
function showCurrent():void{
// make sure they have proper alphas
//prevImage.alpha = 1;
//currentImage.alpha = 0;
//TweenLite.to(prevImage, tweenDuration, { x: -slidesHolder.width } );
twnFlag = true;
if(rt_lt_Flag == true){
TweenLite.to(currentImage, tweenDuration, { x: 0, onUpdate:onTweenProgress, onComplete: removePrevious } );
} else {
TweenLite.to(currentImage, tweenDuration, { x: 0, onUpdate:onTweenProgress, onComplete: removePrevious } );
function onTweenProgress():void{
if(rt_lt_Flag == true){
prevImage.x = currentImage.x - prevImage.width;
} else {
prevImage.x = currentImage.x + prevImage.width;
function removePrevious():void {
if (slidesHolder.contains(prevImage)) slidesHolder.removeChild(prevImage);
twnFlag = false;
function stopScroll(e:MouseEvent):void{
ctrlBox.btnPlay.visible = true;
ctrlBox.btnPause.visible = false;
showTimer.stop();
function startScroll(e:MouseEvent):void{
rt_lt_Flag = true;
ctrlBox.btnPlay.visible = false;
ctrlBox.btnPause.visible = true;
resetListener(timerDuration=5000,tweenDuration=2)
function shwNext(e:MouseEvent):void{
if(twnFlag == false){
rt_lt_Flag = true;
stopScroll(null);
nxtFlag = true;
resetListener(timerDuration=0,tweenDuration=1)
function shwPrev(e:MouseEvent):void{
if(twnFlag == false){
rt_lt_Flag = false;
stopScroll(null);
prvFlag = true;
resetListener(timerDuration=0,tweenDuration=1)
function resetListener(timerDuration,tweenDuration){
showTimer.removeEventListener(TimerEvent.TIMER, slideTransition);
showTimer = new Timer(timerDuration);
showTimer.addEventListener(TimerEvent.TIMER, slideTransition);
showTimer.start();
Can you help me on how can i swap the depth of images and control buttons.
Thanks and regards,
Sreelash -
Help! - as3 IE preloader issues
Ok,
So, I work for the NPS, and they have an outdated CMS. I have no rights to upload an .html file, or edit one that the CMS makes.
SO, I am forced to use their little deal to display my .swf files.
Problem:
http://www.nps.gov/glca/photosmultimedia/ehikes.htm
I made an eHike in as3 Flash CS4. It has two scenes, the first scene is the preload, second is splash content and ehike content. The problem is I cant get the preloader to display in IE. I have all actionscript content exported to the second frame, as talked about here:
http://www.senocular.com/flash/tutor...preloaderstart
and it works fine in firefox.......
GRRRR....
I have tried many different ways to load the preloader..... Here is what I'm currently using....
there is a simple text field for the percentage, and a simple 100 frame animation. preloader_mc
stop();
var preLoaderPercent:Number = 0;
addEventListener(Event.ENTER_FRAME, loadComplete);
function loadComplete(e:Event):void {
if (this.loaderInfo.bytesLoaded == this.loaderInfo.bytesTotal) {
removeEventListener(Event.ENTER_FRAME, loadComplete);
this.loaderInfo.removeEventListener(Event.COMPLETE, loadComplete);
this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, loadProgress);
gotoAndPlay("splash", "content");
}//loadComplete
this.loaderInfo.addEventListener(Event.COMPLETE, loadComplete);
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
function loadProgress(e:ProgressEvent):void {
preLoaderPercent = e.bytesLoaded / e.bytesTotal;
load_txt.text = Math.ceil(preLoaderPercent * 100) + "%";
var animstop:Number = Math.floor(preLoaderPercent*100);
preloader_mc.gotoAndStop(animstop);
The CMS lets you decide in the popup window if it is resizeable or not. This works in IE (stopping people from resizing), but not in firefox, people can resize it. Is there any way to disable the resize in AS3? Again, I understand that your supposed to export the .html file with these settings, but I have no permissions to upload or create new .html files.
Anyone who will help me with this - Thanks
DavidThe problem is talked about here:
http://stackoverflow.com/questions/460677/serving-raw-swf-files-displays-in-firefox-but-no t-in-ie
Solution was to preload with an external .swf
Cheers -
Hi,
Is there a surestarter preloader in AS3 with CS4? Meaning here, showing a progress bar or percentage value before loading the main swf, right away at the start of the loading.
I tried 3 different versions:
1- I used the code from a video (and accompanying files), and simply changed the content.swf to my own swf file (rename my swf content.swf), so that the original code would load my swf instead of the original content.swf. (original content.swf was too small to see anything before loading, because my loading speed is too fast).
Here is the code from the original preloader (loads a small swf which then loads the main swf file):
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
l.load(new URLRequest("content.swf"));
function loop(e:ProgressEvent):void
var perc:Number = e.bytesLoaded / e.bytesTotal;
percent.text = Math.ceil(perc*100).toString();
function done(e:Event):void
removeChildAt(0);
percent = null;
addChild(l);
and here is the link to the file:
http://www.raidcanada.com/preloader-org-test.html
2- used the code suggested, which does the preloading directly in the main swf file:
stop();
//Import the required assets
import flash.display.*;
//Stop the playhead while loading occurs
this.stop();
//Create a listener to call the loading function as the movie loads
this.loaderInfo.addEventListener (ProgressEvent.PROGRESS, PL_LOADING);
/*This is the main function, basically it grabs the total and loaded bytes,
calculates a percentage, and displays it by stretching the bar and adjusting
the textfield display. If your bar/textbox instancenames are NOT lbar/lpc,
you'll need to adjust this code to match your instance names*/
function PL_LOADING(event:ProgressEvent):void {
var pcent:Number=event.bytesLoaded/event.bytesTotal*100;
//Stretch the bar
lbar.scaleX=pcent/100;
//Display the % loaded in textfield
lpc.text=int(pcent)+"%";
//If the movie is fully loaded, kick to the next frame on the main timeline
//You may wish to change the gotoAndStop(2) to a gotoAndPlay(2)
if(pcent==100){
this.gotoAndPlay(2);
This one doesn't work either, and if you refresh the page, you get only the bar, instead of refreshing the main swf.
http://www.raidcanada.com/test/test-2.html
3- use the code suggested to replace the preceding version:
stop();
addEventListener(Event.ENTER_FRAME,checkLoad);
function checkLoad(e:Event):void {
var pcent:Number=this.loaderInfo.bytesLoaded /this.loaderInfo.bytesTotal*100;
lbar.scaleX=pcent/100;
lpc.text=int(pcent)+"%";
if (pcent==100) {
removeEventListener(Event.ENTER_FRAME,checkLoad);
this.gotoAndPlay(2);
This one loads correctly (without the percentage or progress bar) and the refresh is OK.
http://www.raidcanada.com/test/test-1.html
The idea is to have this page load correctly showing a percentage sign and a progress bar until the loading is complete for this page:
http://www.raidcanada.com/entete-multi-hiver-1-test.html
Every time I test the swf directly in Flash CS4 with the simulated download, I get the progress bar and percentage correctly.
I also tried with Firefox and get the same results.
FLAs are at:
http://www.raidcanada.com/test/test-1.fla
http://www.raidcanada.com/test/test-2.fla
and screenshots of FLASH (showing the progress bar in "test movie" with simulated download):
http://www.raidcanada.com/test/screenshot-test-1.jpg
http://www.raidcanada.com/test/screenshot-test-2.jpg
Am I missing something?
THank you in advanceHi,
I am using Internet Explorer 8, version 8.0.7600.16385 with Windows 7 Ultimate or Firefox 3 version 3.5.9
If I flush the cache and load the page:
http://www.raidcanada.com/entete-multi-hiver-1-test.html
It takes about 5 seconds with a blank screen before I get the main swf displayed.
If I load the page: http://www.raidcanada.com/test/test-1.html
It takes about 1 second with a blank screen before I get the main swf displayed. The main swf file is much smaller.
I also did a lot of tests, and still the same problem. Temporarely, on the production site, I ended up installing a static Image saying "Loading", without the code, which then loads the large swf. But some customers are seeing the "Loading" for 14 sec to 24 seconds, depending of the swf file.
I know the code suggested is probably working with CS3 and AS2, but I need to make it work with CS4 and AS3, because my other code is all in AS3, built with CS4. As I said before, if I make a simulation, the simulation is perfect.
Thanks -
My project originally had everything on the timeline, but I have since moved all the code to the document class, but some of my assets are still in the library and some of them are embedded. I'm trying to make a self-preloader that doesn't use any external files, but I can't seem to find a good tutorial that doesn't involve using the timeline. Can anyone point me to a pure AS3 self-preloader tutorial or tell me where I'm supposed to put everything?
If you mean by "self-preloader" a pure Standalone as3 preloader:
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
//this line has to be adapted to the name of your document class
l.load(new URLRequest("main.swf"));
function loop(e:ProgressEvent):void
var kBytesLoaded:int = Math.round(e.bytesLoaded/1024);
var kBytesTotal:int = Math.round(e.bytesTotal/1024);
var perc:Number = kBytesLoaded / kBytesTotal;
trace("PERCENT:"+perc);
function done(e:Event):void
//this line for the stuff you might need to visually communicate the loading process and want to remove when loading is done
removeChildAt(0);
addChild(l); -
Enabling Parent button while external swf is loaded [AS3]
Hello everyone,
I am very new to Flash and it takes me a while to understand what code is trying to tell me
The problem I am currently facing is as follows:
After searching the net for hours I finally figured out, how to load an external swf into my main timeline. As far as I understand this main timeline is the "parent". Hence the loaded, external swf should be the "child" (a quiz).
Now the child (a quiz) loads into the flash file and is played properly, but I cannot access the button on the parent anymore. Unfortunately, I really need the home button on the parent to exit the quiz and allow for new navigation within the flash document.
I would greatly appreciate any help.
Thank you all in advance.
Kliph
my AS3 Code:
import flash.events.MouseEvent;
function onClick611 (event:MouseEvent) :void
gotoAndPlay("home_einf")
home_btn.addEventListener (MouseEvent.CLICK, onClick611);
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
function startLoad()
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("quiz.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
function onCompleteHandler(loadEvent:Event)
addChild(loadEvent.currentTarget.content);
function onProgressHandler(mProgress:ProgressEvent)
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
startLoad();
stop();By simply using addChild like you have, you're placing the loaded content above everything on the display list - covering your button. There are a few ways to solve. The easiest, if it works for you, is to just make a new layer in your timeline - make it the top most layer, and place your home button in that layer.
Then change your addChild line from:
addChild(loadEvent.currentTarget.content);
to:
addChildAt(loadEvent.currentTarget.content, numChildren - 2);
This will place the loaded content behind the button.
Alternatively, you can set the button to export for AS and then add it after you add the loaded file. Or you can use content containers - empty sprites that you add first, and then fill with other objects, in order to control layering. -
AS3 rotation issue/bug need help.
Ok I have been converting a AS2 flash based sight to AS3. With the project I have to make new transitions for the pages. The client wants these transitions to be in 3d, which ive worked with before and have had no problems. However for the last few hours ive had this killer issue that wont go away.
When using rotationZ or rotationX on any element the rotation value is not based on 360 degrease but instead based on a random number. For example I can rotate a box on the stage by 0.03 and it will be ~rotated 180 degrease, but if I do the same rotation on another box on the stage it will go to ~40 degrease.
Im clueless to why this is happing and if I try to duplicate the error in another file it wont happen. So... anyone able to give me a heads up at what may be causing this?
For those asking how im rotating it.
box.rotationY = 45;
box2.rotationY = 90;Ok... heres the min code for the error to happen my side.
If you need an XML you can make your own to test this using the fallowing structer or just use this.
---------------------------- XML Bellow ------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xml>
<page>
<name value="Home"/>
<background value=""/>
<content type="text">Hello this is random text? what the hell? what the duce?</content>
<x value="400"/>
<y value="20"/>
<content type="image">url to the image file</content>
<x value="400"/>
<y value="20"/>
</page>
</xml>
-------------------------------- AS3 Bellow -----------------------------
package {
import com.greensock.*; // this is a tweening class dont worrie about it
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.text.*;
import flash.utils.*;
import flash.geom.*;
public class sps extends MovieClip {
var PAGES:MovieClip = new MovieClip();
var p_url:String="sps.xml"; // this generates content for pages loads and works fine dont worrie about it
var p_loader:URLLoader = new URLLoader();
var PageList:XMLList;
var rdy:Boolean = false;
public function sps() {
setFormats();
loadPages();
init();
public function init() {
addChild(PAGES);
PAGES.rotationY = 60; // This is were the problem is!
public function setFormats() {
ntf.color=0xFFFFFF;
ntf.font="Tahoma";
ntf.size=12;
ntf.align="center";
ntf.bold=true;
ntf.rightMargin=ntf.leftMargin=10;
public function loadPages() {
function onComplete(e:Event) {
p_loader.removeEventListener(Event.COMPLETE, onComplete);
var xmlData:XML=new XML(e.target.data);
PageList=xmlData.children();
var i:Number=0;
while (i < PageList.length()) {
makePage(PageList[i], PAGES);
i+=1;
p_loader.load(new URLRequest(p_url));
p_loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
public function makePage(pd:XML, p:MovieClip) {
var page:MovieClip =new MovieClip();
var pageCon:MovieClip = new MovieClip();
var i:Number=0;
while (i < pd.content.length()) {
if (pd.content[i].attributes()=="text") {
newText(pageCon, pd.content[i], pd.x[i].attributes(), pd.y[i].attributes());
}else if (pd.content[i].attributes()=="image") {
newImage(pageCon, pd.content[i], pd.x[i].attributes(), pd.y[i].attributes());
}else if (pd.content[i].attributes()=="video") {
}else if (pd.content[i].attributes()=="music") {
}else if (pd.content[i].attributes()=="subpage") {
}else if (pd.content[i].attributes()=="slider") {
i += 1;
pageCon.x-=472.5;
p.addChild(pageCon);
pageCon.addChild(page);
public function newText(p:MovieClip, t:String, x:Number, y:Number) {
var tf:TextField = new TextField();
tf.text = t;
tf.x=x;
tf.y=y;
p.addChild(tf);
return tf;
public function newImage(p:MovieClip, u:String, x:Number, y:Number) {
var f:URLRequest = new URLRequest(u);
var i:MovieClip = new MovieClip();
var l:Loader = new Loader();
i.x=x;
i.y=y;
l.load(f);
p.addChild(i);
function ps (e:ProgressEvent){
function lr(e:Event){
l.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, ps);
l.contentLoaderInfo.removeEventListener(Event.COMPLETE, lr);
i.addChild(l);
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, ps);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, lr);
return i; -
Preloader (from as2 to as3)
Hey ladies and gentlemen
I'm currently converting one of my project to as3 and I hit a
wall with this preloader problem.
Before, with as2, I was using getBytesLoaded() and
getBytesTotal() in a frame loop to display a progress bar and know
when the loading was finished. I can't seem to find how to do this
in as3.
I read as3 language reference and some examples but they all
deal with loading an external swf or file.
I would think that the main swf would trigger progress events
as it gets loaded so I made this little piece of code, which
doesn't work.
function ProgressHandler(theEvent:ProgressEvent)
trace("bytes Loaded: " + theEvent.bytesLoaded + "
bytesTotal: " + theEvent.bytesTotal);
addEventListener(ProgressEvent.PROGRESS, ProgressHandler);
stop();
Can anyone point me back in the right direction?
ThanksI just wanna make it clear that I'm trying to preload the
main swf itself, I still can't find anything on the net about that.
Anyone?
Thanks! -
HELP - Add a skip intro btn to AS3 preloader
Hello, I'm a bit of a newbie to AS3 and new some help!
I've created a preloader.swf that (when loaded) loads an external swf. I would also like to add a skip intro btn, but when I do, the preloader seems to loop over and over (blinking - I know, high tech).
This is the preloader code. I have it in the first frame of the preloader.swf:
stop();
var myRequest:URLRequest = new URLRequest("flash/index.swf");
var myLoader:Loader = new Loader();
myLoader.load(myRequest);
myLoader.contentLoaderInfo.addEventListener(Event.OPEN,showPreloader);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,showProgress);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showContent);
var myPreloader:Preloader = new Preloader();
function showPreloader(event:Event):void {
addChild(myPreloader);
myPreloader.x = stage.stageWidth/2;
myPreloader.y = stage.stageHeight/2;
function showProgress(event:ProgressEvent):void {
var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
myPreloader.loading_txt.text = "Loading - " + Math.round(percentLoaded * 100) + "%";
myPreloader.bar_mc.width = 198 * percentLoaded;
function showContent(event:Event):void {
removeChild(myPreloader);
addChild(myLoader);
On it's own, it works fine.
Then I added a MC with the instance name "skipIntro", and then added this script to the script above:
skipIntro.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_2);
function fl_ClickToGoToWebPage_2(event:MouseEvent):void
navigateToURL(new URLRequest("/residences/residences.php"), "_blank");
Any help? Thanks.There doesn't appear to be anything wrong with the code. Does it start behaving correctly again if you comment out that code? Do you get any error messages? The behavior you describe (looping/blinking) is indicative of an unhappy processor.
-
Socket AS3 ( Receive File .TXT ) + Java Socket
Hi,
I have Java Socket sending .TXT file ( 10 MB ) . But the AS3 only gets 63 Kb . I do not understand the loss of bytes ...
Souce Java :
public void sendFile(String fileName) {
try {
//handle file read
File myFile = new File(fileName);
byte[] mybytearray = new byte[(int) myFile.length()];
FileInputStream fis = new FileInputStream(myFile);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
dis.readFully(mybytearray, 0, mybytearray.length);
OutputStream os = clientSocket.getOutputStream();
byte[] fileSize = intToByte(mybytearray.length);
byte[] clientData = new byte[(int) myFile.length() + mybytearray.length];
System.arraycopy(fileSize, 0, clientData, 0, fileSize.length); // Copy to the file size byte array to the sending array (clientData) beginning the in the 0 index
System.arraycopy(mybytearray, 0, clientData, 4, mybytearray.length); // Copy to the file data byte array to the sending array (clientData) beginning the in the 4 index
DataOutputStream dos = new DataOutputStream(os);
//dos.writeUTF(myFile.getName());
//dos.writeInt(mybytearray.length);
dos.write(clientData, 0, clientData.length);
dos.flush();
AS3 Source..
private function onResponse(e:ProgressEvent):void {
var file:File;
var fs:FileStream;
var fileData:ByteArray = new ByteArray();
file = File.documentsDirectory.resolvePath("tmpReceive.txt");
fs = new FileStream();
fs.addEventListener(Event.CLOSE,onCloseFileReceive);
if(_socket.bytesAvailable > 0) {
while(_socket.bytesAvailable) {
// read the socket data into the fileData
_socket.readBytes(fileData,0,0);
fs.open(file, FileMode.WRITE);
// Writing the file
fs.writeBytes(fileData);
fs.close();Crypto streams, like CipherInputStream andCipherOutputStream, do not behave properly until you
issue a close() call. So if you are going to do
crypto, you will need to trap the close() before it
reaches the underlying socket streams. This is
because the close() method finalizes the cryptographic
operation. (Flush() would make more sense, no idea
why they did it this way). You do want to finalize
the crypto for any given message, but you need to trap
the close() before it hits the socket and ends the
whole affair.
I don't see anything about that in the bug database.
No matter what streams you are using, if you aregoing to keep the socket open for multiple
request-response round-trips, you need to very closely
pay attention to how much data is being sent on each
trip. Normally, you can fudge this a bit on a
request-response because the close() call on the
output stream will cause the receiving input stream to
behave more or less properly. However, a flush() will
not.Why not? I use that all the time with no problem.
A good practice is to send the content-length of
the message first, so the receiving input stream
"knows" when to stop reading, does not block, and then
can send its own bytes back the other direction.
(Where the process is repeated).
An alternative is to use two threads: read and write.
The read recieves, parses, validates and then pushes complete messages to a queue.
The write pulls messages from the queue, processes and send a result.
A variation to the above is what happens when an invalid message is received. The server can ignore it, the read can send a error response, or the read can push a message to the queue which causes the write to send a error response. -
Regarding loader Error in flash as3
My project is converting as2 to as3 flash file. In AS2 , I am using "loadmovie" to load the external swf also it gets totalframes of swf . It works correctly. But In as3 i am using "loader" to load the external swf. But the "loader" is not calculated the external swf total frames.Then how to calculate totalframe in as3. plz give any idea
Here is an example of a progress listener and funtion for AS3.
loader.addEventListener(ProgressEvent.PROGRESS, progressHandler);
private function progressHandler(evt:ProgressEvent)
var perc:Number = evt.bytesLoaded / evt.bytesTotal;
if(evt.bytesLoaded == evt.bytesTotal)
evt.target.removeEventListener(ProgressEvent.PROGRESS, progressHandler);
//now you can do something else -
Preloader not working in AS3 when viewing in a browser
Hi there, It's me again Ysong.
I have a problem regarding PRELOADING.
MY TIMELINE:
• First frame -- dynamic text which is my preloader with AS3 in it. NO MORE OBJECT in the frame only text which is dynamic.
stop();
loaderInfo.addEventListener(ProgressEvent.PROGRESS, updatePreloader);
function updatePreloader(evtObj:ProgressEvent):void
var percent:Number = Math.floor((evtObj.bytesLoaded*100)/evtObj.bytesTotal);
myLoadText.text = "Loading..." + percent+"%";
if (percent==100){
nextFrame();
• Second frame -- the whole site in MOVIE CLIP which will be loaded after the preloading ends.
***The whole SWF file is only 600KB when publishing.
***When simulating download the preloader is working.
MY PROBLEM:
Whenever I uploaded these two files: (1) index.swf and (2) index.html, the preloader doesn't work. When viewed in browser it apprears to be white screen. After a couple of minutes, the index.swf appears and the preloader is not appearing as it should be. With (2), I didn't change anything on Dreamweaver just upload the file published by Flash Professional CS4.
WHAT IS THE PROBLEM? Can anyone help me with this. I've uploaded (PUT) the files through Dreamweaver with a testing server configured.
Thank you & Regards,
YSONGhi Ned,
I currently downloading the tutorial link you posted.
Do you have any idea what is really happening? Because I really wanted to have a loading text only before the whole site is loaded. The SIMULATED DOWNLOAD in Flash CS4 is working great but whenever copy it in my hosting server and view it in my browser the preloader is not working.
Thank you for your immediate response.
Regards,
YSONG
Maybe you are looking for
-
Sales order from Service Contract?
Dear SD Guru, Can I created Sales Order from Service Contract? I would like to create a sales order from service contract (MV) and I need to generate billing from the sales order. MV-> OR-> F2. No Resource Related Billing involved. Thanks, Soo
-
How do I remove Adobe Bridge (Bridge.EXE).
I am unable to install Adobe illustrator Master suite because I get an error message to remove Bridge.EXE, but I can not find it on my PC anyuwhere. Can anyone help me get this removed?
-
Apple Video Trailers not working/Memory Hog
Hello, When I go to apple.com/trailers, the trailers do not display I keep seeing that grey wheel turn endlessly. When I try to view it in Firefox, it works perfectly fine. Anyone know why Safari would be doing this? Another issue that I have is that
-
How do I know I am on the iCloud, I never signed up for it, and should not be in/on it. How do I get out of the iCloud if I am indeed in/on it.
-
For each(var mc:MovieClip ..
I have a "for each" loop in my framescript but it seems find nothing because the code inside it isn't executed. I can see the movieclips in the debugger. for each(var mc:MovieClip in MovieClip (this)){ trace(mc.name) Any ideas what is wrong here?