ConfigParser.as 2.28 KB
Newer Older
Anssi Piirainen's avatar
Anssi Piirainen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*    
 *    Copyright (c) 2008-2011 Flowplayer Oy *
 *    This file is part of Flowplayer.
 *
 *    Flowplayer is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    Flowplayer is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with Flowplayer.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.flowplayer.config {

    import org.flowplayer.controller.ResourceLoader;
    import org.flowplayer.flow_internal;
	import org.flowplayer.util.Log;
24
	import com.adobe.serialization.json.JSONforFP;
Anssi Piirainen's avatar
Anssi Piirainen committed
25
26
27
28
29
30
31
32
33
34
35

    use namespace flow_internal;

	/**
	 * @author anssi
	 */
	public class ConfigParser {
		private static var log:Log = new Log(ConfigParser);

        flow_internal static function parse(config:String):Object {
            //#590 add full package reference to work with Flex 4.6
36
            return com.adobe.serialization.json.JSONforFP.decode(config);
Anssi Piirainen's avatar
Anssi Piirainen committed
37
38
39
40
        }

        flow_internal static function parseConfig(config:Object, builtInConfig:Object, playerSwfUrl:String, controlsVersion:String, audioVersion:String):Config {
            if (!config) return new Config({}, builtInConfig, playerSwfUrl, controlsVersion, audioVersion);
41
            var configObj:Object = config is String ? com.adobe.serialization.json.JSONforFP.decode(config as String) : config;
Anssi Piirainen's avatar
Anssi Piirainen committed
42
43
44
45
46
47
48
49
50
51
52
            return new Config(configObj, builtInConfig, playerSwfUrl, controlsVersion, audioVersion);
        }

        flow_internal static function loadConfig(fileName:String, builtInConfig:Object, listener:Function, loader:ResourceLoader, playerSwfName:String, controlsVersion:String, audioVersion:String):void {
            loader.load(fileName, function(loader:ResourceLoader):void {
                //trace(loader.getContent());
                listener(parseConfig(loader.getContent(), builtInConfig, playerSwfName, controlsVersion, audioVersion))
            }, true);
        }
	}
}