Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3501134
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:49:16+00:00 2026-05-18T12:49:16+00:00

Using Flash Builder 4 (with 4.1 flex). Trying to create a state change after

  • 0

Using Flash Builder 4 (with 4.1 flex).
Trying to create a state change after my function has finished running that will change the screen to have a “finished” button that will close the application. How can I tell the air app to do this?
I found this: protected function setState(newState:String):void for AS3 but won’t work on flex 4. It should change state to Finished after the array of files is done.

        private function initiate_download(event:MouseEvent):void
        {
            var filearray:Array = new Array();
            filearray[0]="00.jpg";
            filearray[1]="01.jpg";
            filearray[2]="02.jpg";
            for (var i:uint; i < filearray.length; i++) {
                var remoteURL = "http://domain/" + filearray[i];
                var localURL = "C:/dir/" + filearray[i];
                downloadFile(remoteURL, localURL);
            }


            function downloadFile(url, filename) {
                // Create the stream for the data request
                var urlStream = new URLStream();

                // Used to initiate request for remote file
                var request = new URLRequest(url);

                // Create file stream
                var fileStream = new FileStream();

                // Create a reference to a location on disk
                var file = File.desktopDirectory.resolvePath(filename);

                // Called as download progresses
                var writeFile = function()
                {
                    // Write to file
                    if (urlStream.bytesAvailable > 51200)
                    {
                        var dataBuffer = new ByteArray();
                        urlStream.readBytes(dataBuffer, 0, urlStream.bytesAvailable);
                        fileStream.writeBytes(dataBuffer, 0, dataBuffer.length);
                    }
                    return true;
                }

                // Called when download completes
                var finishWriteFile = function()
                {
                    // Write to file
                    if(urlStream.bytesAvailable > 0)
                    {
                        var dataBuffer = new ByteArray();
                        urlStream.readBytes(dataBuffer, 0, urlStream.bytesAvailable);
                        fileStream.writeBytes(dataBuffer, 0, dataBuffer.length);
                    }

                    // Close streams
                    fileStream.close();
                    urlStream.close();

                    return true;
                }

                // Initiate download
                fileStream.openAsync(file, FileMode.WRITE);
                urlStream.load(request);

                // Add event listeners
                urlStream.addEventListener(Event.COMPLETE, finishWriteFile);
                urlStream.addEventListener(ProgressEvent.PROGRESS, writeFile);
            }
    ]]>
</fx:Script>
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:states>
    <s:State name="Start"/>
    <s:State name="Finished"/>
</s:states>
<mx:Image x="0" y="0" source="background.jpg"/>
<s:Button x="85" y="85" includeIn="Start" label="Update" id="download" click="initiate_download(event)" color="#FFFFFF" fontSize="30"/>
<s:Button x="131" y="85" includeIn="Finished" label="Finished" id="closer" click="close_window(event)" color="#FFFFFF" fontSize="30"/>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:49:16+00:00Added an answer on May 18, 2026 at 12:49 pm

    after you close the fileStream and urlStream you can change state doing

    this.currentState = "Finished"
    

    and the close button should be visible now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Flash builder, with flex 4 sdk and am trying to create a
How do I change text color using flash actionscript 2?
A site I'm working on has Flash headers (using swfobject to embed them). Now
How do you trigger a javascript function using actionscript in flash? The goal is
I'm creating an actionscript project in Flex Builder. I succeed to export from Flash
I'm trying to use the Flex 4 SDK's mx.rpc package in a Flash application.
since I'm using custom skin classes in Flex I'm getting an error, when trying
I'm making a change to a set of code for a Flex project that
I'm trying the sample demo of selenium flex API . After following the instructions
I'm using Flash to play an .flv movieclip on my site, but I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.