Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Flex > Flex 2, 3 & 4

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-17-2006, 05:47 PM   #1
vistasoul
Registered User
 
Join Date: Apr 2005
Posts: 32
Default Calling an event in application from .as class file

Hello,

I have an .as Class file that have a few event handlers in it.... I'm using this class to upload files to my server... here is the code.

Code:
package as3
{
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.FileReference;
    import flash.net.URLRequest;

    public class FileUpload extends Sprite {
        private var uploadURL:URLRequest;
        private var file:FileReference;

        public function FileUpload() {
            uploadURL = new URLRequest();
            uploadURL.url = "http://www.mywebsite.com/upload.php";
            file = new FileReference();
            file.addEventListener(Event.SELECT, selectHandler);
            file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            file.addEventListener(Event.COMPLETE, completeHandler);
        }
        
        public function FileBrowse():void
        {
        	file.browse();
        }

        private function selectHandler(event:Event):void {
            var file:FileReference = FileReference(event.target);
            file.upload(uploadURL);
        }

        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }

        private function progressHandler(event:ProgressEvent):void {
            var file:FileReference = FileReference(event.target);
            trace("progressHandler: name=" + file.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
        }

        private function completeHandler(event:Event):void {
            trace("completeHandler: " + event);
        }
    }
}
^^ How can I fire an event in my main application using one of those event handlers?

For example.. I'm trying to change the currentState of my appliction using the selectHandler above.

in my main application all I have to do is call "this.currentState="state"; and it works... but I don't know how to do this from within my class file.

Thank you.
vistasoul is offline   Reply With Quote
Old 07-19-2006, 09:31 AM   #2
hangalot
lala
 
hangalot's Avatar
 
Join Date: Feb 2002
Location: on the road
Posts: 2,858
Default

you need to add a listener to your class and dispatch an event you listen to somewhere else
__________________
oi poloi
http://www.memorphic.com/news/
hangalot is offline   Reply With Quote
Old 02-02-2007, 10:24 PM   #3
DangerAhead
Registered User
 
Join Date: Jan 2007
Posts: 3
Default FileReference Error 2038

if you run into the Error #2038. AND you're using FireFox you might want to read this important thread:

http://tech.groups.yahoo.com/group/f.../message/55890

it says Firefox has problems handing the FileReference over to the browser. I can't seem to get FileReference to work in FireFox 1.5.
DangerAhead is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pre-loading multiple files - SOLUTION Prpl_Ppl_Etr ActionScript 2.0 2 07-29-2008 06:39 PM
Using the mx.util.Delegate class within your classes! madgett ActionScript 2.0 3 09-02-2007 11:11 PM
using a Class file to return an XML value dan_d ActionScript 2.0 3 03-26-2006 05:56 PM
class and event dispatcher. Skindc ActionScript 2.0 2 10-07-2005 03:04 PM
card game: designing Deck class and good OOP? pigpen Gaming and Game Development 1 11-26-2002 11:41 AM


All times are GMT. The time now is 03:22 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.