| 1 | package com.longtailvideo.jwplayer.view.skins { |
|---|
| 2 | import com.longtailvideo.jwplayer.utils.AssetLoader; |
|---|
| 3 | import com.longtailvideo.jwplayer.utils.Strings; |
|---|
| 4 | import com.nochump.util.zip.ZipEntry; |
|---|
| 5 | import com.nochump.util.zip.ZipFile; |
|---|
| 6 | |
|---|
| 7 | import flash.events.ErrorEvent; |
|---|
| 8 | import flash.events.Event; |
|---|
| 9 | import flash.events.IOErrorEvent; |
|---|
| 10 | import flash.events.SecurityErrorEvent; |
|---|
| 11 | import flash.net.URLRequest; |
|---|
| 12 | import flash.net.URLStream; |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | public class ZIPSkin extends PNGSkin { |
|---|
| 16 | private var _zipFile:ZipFile; |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | public function ZIPSkin() { |
|---|
| 20 | super(); |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | public override function load(url:String=null):void { |
|---|
| 25 | if (Strings.extension(url) == "zip") { |
|---|
| 26 | _urlPrefix = url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('.')); |
|---|
| 27 | |
|---|
| 28 | var urlStream:URLStream = new URLStream(); |
|---|
| 29 | urlStream.addEventListener(Event.COMPLETE, loadComplete); |
|---|
| 30 | urlStream.addEventListener(IOErrorEvent.IO_ERROR, loadError); |
|---|
| 31 | urlStream.addEventListener(SecurityErrorEvent.SECURITY_ERROR, loadError); |
|---|
| 32 | urlStream.load(new URLRequest(url)); |
|---|
| 33 | } else if (_skin.numChildren == 0) { |
|---|
| 34 | sendError("ZIP skin descriptor file must have a .zip extension"); |
|---|
| 35 | } |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | protected override function loadComplete(evt:Event):void { |
|---|
| 40 | var data:URLStream = URLStream(evt.target); |
|---|
| 41 | _zipFile = new ZipFile(data); |
|---|
| 42 | try { |
|---|
| 43 | var zipEntry:ZipEntry = _zipFile.getEntry(_urlPrefix + '.xml'); |
|---|
| 44 | if (!zipEntry) { |
|---|
| 45 | zipEntry = _zipFile.getEntry(_urlPrefix+'/'+_urlPrefix + '.xml'); |
|---|
| 46 | } else { |
|---|
| 47 | _urlPrefix = null; |
|---|
| 48 | } |
|---|
| 49 | _skinXML = XML(String(_zipFile.getInput(zipEntry))); |
|---|
| 50 | parseSkin(); |
|---|
| 51 | } catch (e:Error) { |
|---|
| 52 | sendError(e.message); |
|---|
| 53 | } |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | protected override function loadElements(component:String, elements:XMLList):void { |
|---|
| 58 | if (!component) |
|---|
| 59 | return; |
|---|
| 60 | |
|---|
| 61 | for each (var element:XML in elements) { |
|---|
| 62 | var file:String = component + '/' + element.@src.toString(); |
|---|
| 63 | if (_urlPrefix){ |
|---|
| 64 | file = _urlPrefix +'/'+file; |
|---|
| 65 | } |
|---|
| 66 | var zipEntry:ZipEntry = _zipFile.getEntry(file); |
|---|
| 67 | |
|---|
| 68 | if (zipEntry) { |
|---|
| 69 | try { |
|---|
| 70 | var newLoader:AssetLoader = new AssetLoader(); |
|---|
| 71 | _loaders[newLoader] = {componentName: component, elementName: element.@name.toString()}; |
|---|
| 72 | newLoader.addEventListener(Event.COMPLETE, elementHandler); |
|---|
| 73 | newLoader.addEventListener(ErrorEvent.ERROR, elementError); |
|---|
| 74 | newLoader.loadBytes(_zipFile.getInput(zipEntry)); |
|---|
| 75 | } catch (err:Error) { |
|---|
| 76 | sendError("Error loading ZIP skin "+component+"'s "+element.toString()+": "+err.message); |
|---|
| 77 | } |
|---|
| 78 | } |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | } |
|---|