7

I would like to read the source of the flash.net.FileReference class. Is this possible? Where can I find the source files, do they come with the Adobe Flash or Flash Builder?

jayarjo
  • 16,124
  • 24
  • 94
  • 138
  • 4
    what is it that you would like to change? I would recommend creating a custom class that extends FileReference and override the functions you want to change. – Corey May 18 '11 at 14:52
  • Well yes, your way of doing it is definitely cleaner, but that's not the main point - can I read them? Anywhere? – jayarjo May 18 '11 at 15:03

3 Answers3

6

To read the flash package files, you can find the playerglobal.swc - change the name to playerglobal.zip and unzip the package. Then, decompile the library.swf file and get the script files. Here's what I found for FileReference:

//FileReference
package flash.net 
{
    import flash.events.*;
    import flash.utils.*;

    public class FileReference extends flash.events.EventDispatcher
    {
        public function FileReference()
        {
            super();
            return;
        }

        public function upload(arg1:flash.net.URLRequest, arg2:String="Filedata", arg3:Boolean=false):void
        {
        }

        private function _load(arg1:flash.utils.ByteArray):void
        {
        }

        public function load():void
        {
            this._load(new ByteArray());
            return;
        }

        public function get size():uint
        {
        }

        public function get type():String
        {
        }

        public function browse(arg1:Array=null):Boolean
        {
        }

        public function get name():String
        {
        }

        public function get creator():String
        {
        }

        public function get creationDate():Date
        {
        }

        public function download(arg1:flash.net.URLRequest, arg2:String=null):void
        {
        }

        public function get modificationDate():Date
        {
        }

        public function get data():flash.utils.ByteArray
        {
        }

        public function cancel():void
        {
        }

        private function _save(arg1:flash.utils.ByteArray, arg2:String):void
        {
        }

        public function save(arg1:*, arg2:String=null):void
        {
            var defaultFileName:String=null;
            var data:*;
            var d:flash.utils.ByteArray;

            var loc1:*;
            data = arg1;
            defaultFileName = arg2;
            d = new ByteArray();
            if (data == null) 
            {
                throw new ArgumentError("data");
            }
            if (data is String) 
            {
                d.writeUTFBytes(data as String);
            }
            else if (data is XML) 
            {
                d.writeUTFBytes((data as XML).toXMLString());
            }
            else if (data is ByteArray) 
            {
                d.writeBytes(data as ByteArray);
            }
            else 
            {
                try 
                {
                    d.writeUTFBytes(data);
                }
                catch (e:Error)
                {
                    throw new ArgumentError("data");
                }
            }
            d.position = 0;
            if (defaultFileName == null) 
            {
                defaultFileName = "";
            }
            this._save(d, defaultFileName);
            return;
        }
    }
}

I highly recommend not changing this file and rather extend it and override the functions you need to modify. Otherwise, you'll need to recompile the library.swf and create a custom playerglobal.swc.

Corey
  • 5,818
  • 2
  • 24
  • 37
  • What those dummy methods stand for? Is FileReference actually an example of a intrinsic class, that might not be changed? Actually I wondered how does upload() method manage direct streaming, without loading the file into memory and maybe mimic it somehow in my app. I do not mind to do some monkey patching if it's possible to achieve this somehow. – jayarjo May 19 '11 at 08:05
3

As others mentioned you can see the sources for the Flash and Flex framework classes. The exact location will vary.

For Flash CS4 on Windows 7:

C:\Users\<your_user>\AppData\Local\Adobe\Flash CS4\en\Configuration

For Flex:

...\flex_sdk\frameworks\projects\framework\src

You CAN change any framework class you want as long as you're careful. In Flash nomenclature this is referred to as Monkey Patching. Create a class in your project with the same full package structure and class name as the framework class and the compiler will find and use your custom class instead of the framework class.

There are some complications in doing this with framework RSL's. For that see here:

How to Monkey Patch when using Flex RSLs

http://blogs.adobe.com/dloverin/2010/01/how_to_monkey_patch_when_using_flex_rsls.html

This does not apply to built-in or "intrinsic" classes. Those are built-into the player and wills till have stub code in the above source locations. You can't actually change intrinsic classes.

Samuel Neff
  • 73,278
  • 17
  • 138
  • 182
  • Thanks for insightful post - very informative. Is FileReference intrinsic class then? – jayarjo May 19 '11 at 10:05
  • 2
    @jayarjo, yes, FileReference is intrinsic, or at least partially intrinsic. Look at the source and you'll see that many of the methods are empty. That's because the code for them is native code provided by the runtime. – Samuel Neff May 19 '11 at 11:32
0

Any of the "stuff" that is available for you to view are located (for Win7 anyway) in C:\Users\<your_user>\AppData\Local\Adobe\Flash CS4\en\Configuration

The Flash CS4 portion might change depending on the version you have. Classes are in the Classes folder inside configuration.

Alex Jillard
  • 2,792
  • 2
  • 19
  • 20