A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: need to execute a statement after a function is completely done

  1. #1
    Member
    Join Date
    Jan 2006
    Posts
    45

    need to execute a statement after a function is completely done

    Hi,

    I need to have something execute after a function is completed.
    Code:
    uploadButton_mc.onRelease = uploadCurrent;
    
    function uploadCurrent():Void {
    	chooseButton_mc._visible = false;
    	progressBar = makeProgressBar(0, progressBarY);
    	reference.upload(scriptLocation);
    	
    }
    I basically need to make the following code happen after everything in uploadCurrent is 100% done:

    Code:
    MyVars.load ('php_scripts/flash_interact.php?action=initialize');
    Inserting this line inside the uploadCurrent function doesn't work because the line executes before the other lines are completely done.

    Thanks for your help

  2. #2
    Member
    Join Date
    Jan 2006
    Posts
    45
    BTW, I need it to happen every time the uploadCurrent function is called.

  3. #3
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    if(upload ==100%){
    MyVars.load ('php_scripts/flash_interact.php?action=initialize');

    }
    ~calmchess~

  4. #4
    Member
    Join Date
    Jan 2006
    Posts
    45
    can you do that? I get this error:

    **Error** Scene=Scene 1, layer=a, frame=1:Line 127: Operator '%' must be followed by an operand
    if(upload ==100%){

  5. #5
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    I'm sorry it was meant to be abstract code just what you need to write to execute a function afterwards........I couldn't give you a more definate example because from the looks of your code you still have alot of work to do before you will be able to upload anything.
    ~calmchess~

  6. #6
    Member
    Join Date
    Jan 2006
    Posts
    45
    oops, I actually simplified the code to make it easier on anyone trying to help. Here's at least the whole file upload part. Keep in mind that the MyVars stuff is set up before this. I just need to execute it after a file has uploaded.

    Code:
    import flash.net.FileReference;
    var progressBar:MovieClip;
    var reference:FileReference = new FileReference();
    var referenceListener:Object = {};
    var scriptLocation:String = 'php_scripts/flash_interact.php?action=add&profile_id=11' + _root.profile_id;
    var progressBarHeight:Number = 10;
    var progressBarY:Number = 50;
    var progressBarColor:Number = 0x66ccff;
    uploadButton_mc._visible = false;
    reference.addListener(referenceListener);
    referenceListener.onSelect = activateUploadButton;
    referenceListener.onProgress = updateProgress;
    referenceListener.onComplete = restart;
    referenceListener.onHTTPError = handleError;
    referenceListener.onIOError = handleError;
    referenceListener.onSecurityError = handleError;
    chooseButton_mc.onRelease = choose;
    uploadButton_mc.onRelease = uploadCurrent;
    function activateUploadButton():Void {
    	display_txt.text = reference.name;
    	uploadButton_mc._visible = true;
    }
    function choose():Void {
    	reference.browse([{description:'All Files (*.*)', extension:'*.*'}]);
    }
    function handleError(errorName:String, detail:Object):Void {
    	restart();
    	if (arguments.length === 2) {
    		if (typeof detail === 'number') {
    			display_txt.text = 'HTTP Error #'+detail;
    		} else {
    			display_txt.text = 'Security Error: '+detail;
    		}
    	} else {
    		display_txt.text = 'IO Error';
    	}
    }
    function makeProgressBar(x:Number, y:Number):MovieClip {
    	var bar:MovieClip = createEmptyMovieClip('progressBar_mc', 0);
    	bar._visible = false;
    	bar.beginFill(progressBarColor);
    	bar.lineTo(Stage.width, 0);
    	bar.lineTo(Stage.width, progressBarHeight);
    	bar.lineTo(0, progressBarHeight);
    	bar.lineTo(0, 0);
    	bar.endFill();
    	bar._width = 0;
    	bar._visible = true;
    	bar._x = x;
    	bar._y = y;
    	return bar;
    }
    function restart():Void {
    	removeMovieClip(progressBar);
    	display_txt.text = '';
    	uploadButton_mc._visible = false;
    	chooseButton_mc._visible = true;
    }
    function updateProgress(fileReference:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
    	display_txt.text = fileReference.name+' - '+Math.ceil((bytesLoaded/bytesTotal)*100)+'%';
    	progressBar._width = Math.ceil(Stage.width*(bytesLoaded/bytesTotal));
    }
    function uploadCurrent():Void {
    	chooseButton_mc._visible = false;
    	progressBar = makeProgressBar(0, progressBarY);
    	reference.upload(scriptLocation);
    	
    }

  7. #7
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    Everything I changed is in bold type.


    Code:
    import flash.net.FileReference;
    var progressBar:MovieClip;
    var reference:FileReference = new FileReference();
    var referenceListener:Object = {};
    var scriptLocation:String = 'php_scripts/flash_interact.php?action=add&profile_id=11' + _root.profile_id;
    var progressBarHeight:Number = 10;
    var progressBarY:Number = 50;
    var progressBarColor:Number = 0x66ccff;
    uploadButton_mc._visible = false;
    reference.addListener(referenceListener);
    referenceListener.onSelect = activateUploadButton;
    referenceListener.onProgress = updateProgress;
    referenceListener.onComplete = restart;
    referenceListener.onHTTPError = handleError;
    referenceListener.onIOError = handleError;
    referenceListener.onSecurityError = handleError;
    chooseButton_mc.onRelease = choose;
    uploadButton_mc.onRelease = uploadCurrent;
    function activateUploadButton():Void {
    	display_txt.text = reference.name;
    	uploadButton_mc._visible = true;
    }
    function choose():Void {
    	reference.browse([{description:'All Files (*.*)', extension:'*.*'}]);
    }
    function handleError(errorName:String, detail:Object):Void {
    	restart();
    	if (arguments.length === 2) {
    		if (typeof detail === 'number') {
    			display_txt.text = 'HTTP Error #'+detail;
    		} else {
    			display_txt.text = 'Security Error: '+detail;
    		}
    	} else {
    		display_txt.text = 'IO Error';
    	}
    }
    function makeProgressBar(x:Number, y:Number):MovieClip {
    	var bar:MovieClip = createEmptyMovieClip('progressBar_mc', 0);
    	bar._visible = false;
    	bar.beginFill(progressBarColor);
    	bar.lineTo(Stage.width, 0);
    	bar.lineTo(Stage.width, progressBarHeight);
    	bar.lineTo(0, progressBarHeight);
    	bar.lineTo(0, 0);
    	bar.endFill();
    	bar._width = 0;
    	bar._visible = true;
    	bar._x = x;
    	bar._y = y;
    	return bar;
    }
    function restart():Void {
    	removeMovieClip(progressBar);
    	display_txt.text = '';
    	uploadButton_mc._visible = false;
    	chooseButton_mc._visible = true;
    }
    function updateProgress(fileReference:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
    
    
    	var tot = fileReference.name+' - '+Math.ceil((bytesLoaded/bytesTotal)*100)+'%';
    display_txt.text = tot;
    if(tot == "100%"){
    
    MyVars.load ('php_scripts/flash_interact.php?action=initialize');
    
    
    }
    
    	progressBar._width = Math.ceil(Stage.width*(bytesLoaded/bytesTotal));
    }
    function uploadCurrent():Void {
    	chooseButton_mc._visible = false;
    	progressBar = makeProgressBar(0, progressBarY);
    	reference.upload(scriptLocation);
    	
    }
    ~calmchess~

  8. #8
    Member
    Join Date
    Jan 2006
    Posts
    45
    thanks a million. However, the change made me realize I have another frustrating issue. It seems I'm doing something wrong getting the scriptLocation variable to output right. This is where the variable profile_id is born:
    Code:
    MyVars = new LoadVars ();
    MyVars.onLoad = function () {
    	//save profile_id to pass to uploader
    	_root.profile_id= MyVars.profile_id;
    	//save songs for this user
       songsArray = serial.unserialize(this.initSongsPHP);
    	len = songsArray.length;
      for(var i=0; i<len; i++){
       songDisplay.text += songsArray[i] + "\n";
      }
      
    
    };
    MyVars.load ('php_scripts/flash_interact.php?action=initialize');
    later...

    Code:
    var scriptLocation:String = 'php_scripts/flash_interact.php?action=add&profile_id' + _root.profile_id;
    the profile_id variable doesn't seem to make it to the URL variable here.
    Last edited by dangeorge6; 02-22-2007 at 02:31 PM.

  9. #9
    Member
    Join Date
    Jan 2006
    Posts
    45
    I added an = that i forgot to

    var scriptLocation:String = 'php_scripts/flash_interact.php?action=add&profile_id' + _root.profile_id;

    but still no luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center