<commit_before>//
// Flambe - Rapid game development
// https://github.com/aduros/flambe/blob/master/LICENSE.txt

package flambe.platform.flash;

import flash.display.Bitmap;
import flash.display.Loader;
import flash.errors.Error;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.IEventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Sound;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.system.Capabilities;
import flash.system.LoaderContext;

import flambe.asset.AssetEntry;
import flambe.asset.Manifest;
import flambe.platform.BasicAssetPackLoader;

class FlashAssetPackLoader extends BasicAssetPackLoader
{
    public function new (manifest :Manifest)
    {
        super(manifest);
    }

    override private function loadEntry (entry :AssetEntry)
    {
        var dispatcher :IEventDispatcher = null;
        var req = new URLRequest(entry.url);

        switch (entry.type) {
            case Image:
                var loader = new Loader();
                dispatcher = loader.contentLoaderInfo;
                dispatcher.addEventListener(Event.COMPLETE, function (_) {
                    var bitmap :Bitmap = cast loader.content;
                    handleLoad(entry, new FlashTexture(bitmap.bitmapData));
                });
                var ctx = new LoaderContext();
                ctx.checkPolicyFile = true;
                try {
                    loader.load(req, ctx);
                } catch (error :Error) {
                    promise.error.emit(error.message);
                }

            case Audio:
                var sound = new Sound(req);
                dispatcher = sound;
                dispatcher.addEventListener(Event.COMPLETE, function (_) {
                    handleLoad(entry, new FlashSound(sound));
                });

            case Data:
                var urlLoader = new URLLoader();
                dispatcher = urlLoader;
                dispatcher.addEventListener(Event.COMPLETE, function (_) {
                    handleLoad(entry, urlLoader.data);
                });
                try {
                    urlLoader.load(req);
                } catch (error :Error) {
                    promise.error.emit(error.message);
                }
        }

        dispatcher.addEventListener(Event.COMPLETE, function (_) {
            dispatcher = null;
        });<commit_msg>handleError is a shortcut for this.<commit_after>//
// Flambe - Rapid game development
// https://github.com/aduros/flambe/blob/master/LICENSE.txt

package flambe.platform.flash;

import flash.display.Bitmap;
import flash.display.Loader;
import flash.errors.Error;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.IEventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Sound;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.system.Capabilities;
import flash.system.LoaderContext;

import flambe.asset.AssetEntry;
import flambe.asset.Manifest;
import flambe.platform.BasicAssetPackLoader;

class FlashAssetPackLoader extends BasicAssetPackLoader
{
    public function new (manifest :Manifest)
    {
        super(manifest);
    }

    override private function loadEntry (entry :AssetEntry)
    {
        var dispatcher :IEventDispatcher = null;
        var req = new URLRequest(entry.url);

        switch (entry.type) {
            case Image:
                var loader = new Loader();
                dispatcher = loader.contentLoaderInfo;
                dispatcher.addEventListener(Event.COMPLETE, function (_) {
                    var bitmap :Bitmap = cast loader.content;
                    handleLoad(entry, new FlashTexture(bitmap.bitmapData));
                });
                var ctx = new LoaderContext();
                ctx.checkPolicyFile = true;
                try {
                    loader.load(req, ctx);
                } catch (error :Error) {
                    handleError(error.message);
                }

            case Audio:
                var sound = new Sound(req);
                dispatcher = sound;
                dispatcher.addEventListener(Event.COMPLETE, function (_) {
                    handleLoad(entry, new FlashSound(sound));
                });

            case Data:
                var urlLoader = new URLLoader();
                dispatcher = urlLoader;
                dispatcher.addEventListener(Event.COMPLETE, function (_) {
                    handleLoad(entry, urlLoader.data);
                });
                try {
                    urlLoader.load(req);
                } catch (error :Error) {
                    handleError(error.message);
                }
        }

        dispatcher.addEventListener(Event.COMPLETE, function (_) {
            dispatcher = null;
        });
{'fraction_non_alphanumeric': 0.09085439229843562, 'fraction_numerical': 0.0, 'mean_word_length': 1.8876664736537347, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7385050', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1234, 'n_words': 273}