1 /* 2 * Copyright the original author or authors. 3 * 4 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.mozilla.org/MPL/MPL-1.1.html 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import org.as2lib.core.BasicClass; 18 import org.as2lib.data.type.Byte; 19 import org.as2lib.env.reflect.ReflectUtil; 20 import org.as2lib.io.file.MediaFile; 21 22 /** 23 * {@code SwfFile} holds all information of a loaded SWF-file. 24 * 25 * <p>Note that this file can also be used to represent images. 26 * 27 * @author Martin Heidegger 28 * @version 1.0 29 */ 30 class org.as2lib.io.file.SwfFile extends BasicClass implements MediaFile { 31 32 /** Size of the file in bytes. */ 33 private var size:Byte; 34 35 /** Location of the file. */ 36 private var uri:String; 37 38 /** Container of the loaded MovieClip */ 39 private var container:MovieClip; 40 41 /** 42 * Constructs a new {@code SwfFile}. 43 * 44 * @param container {@code MovieClip} that contains the loaded {@code .swf} 45 * @param uri (optional) URI to use as location ({@code container._url} will 46 * be used as default). 47 * @param size (optional) size of the loaded {@code .swf} 48 * ({@code container.getBytesTotal()} will be used as default.) 49 */ 50 public function SwfFile(container:MovieClip, uri:String, size:Byte) { 51 if (!size) { 52 size = new Byte(container.getBytesTotal()); 53 } 54 if (!uri) { 55 uri = container._url; 56 } 57 this.size = size; 58 this.uri = uri; 59 this.container = container; 60 } 61 62 /** 63 * Returns the container to the resource. 64 * 65 * @return {@code MovieClip} that contains the {@code .swf} 66 */ 67 public function getContainer(Void):MovieClip { 68 return container; 69 } 70 71 /** 72 * Returns the location of the resource corresponding to the content. 73 * 74 * <p>Note: Might be the URI of the resource or null if its not requestable 75 * or the internal location corresponding to the instance path (if its without 76 * any connection to a real file). 77 * 78 * @return location of the resource related to the content 79 */ 80 public function getLocation(Void):String { 81 return uri; 82 } 83 84 /** 85 * Returns the size of the file in bytes. 86 * 87 * @return size of the file in bytes 88 */ 89 public function getSize(Void):Byte { 90 return size; 91 } 92 93 /** 94 * Extended Stringifier 95 * 96 * Example: 97 * {@code [type org.as2lib.io.file.SwfResource | Location: MyFile.txt; Size: 12KB; ]} 98 * 99 * @return the {@code SwfResource} as string 100 */ 101 public function toString():String { 102 var result:String; 103 result = "[type " + ReflectUtil.getTypeNameForInstance(this) 104 + " | Location: " + getLocation() 105 + "; Size: " + getSize().toString(false, 2) 106 + "; ]"; 107 return result; 108 } 109 }