* Load content from package * 从包加载内容
(itemURL: string)
| 346 | * 从包加载内容 |
| 347 | */ |
| 348 | protected loadFromPackage(itemURL: string): void { |
| 349 | this._contentItem = UIPackage.getItemByURL(itemURL); |
| 350 | |
| 351 | if (this._contentItem) { |
| 352 | // Get branch and high resolution versions |
| 353 | const branchItem = this._contentItem.getBranch(); |
| 354 | this.sourceWidth = branchItem.width; |
| 355 | this.sourceHeight = branchItem.height; |
| 356 | |
| 357 | const hiResItem = branchItem.getHighResolution(); |
| 358 | hiResItem.load(); |
| 359 | |
| 360 | if (this._autoSize) { |
| 361 | this.setSize(this.sourceWidth, this.sourceHeight); |
| 362 | } |
| 363 | |
| 364 | if (hiResItem.type === EPackageItemType.Image) { |
| 365 | if (!hiResItem.texture) { |
| 366 | this.setErrorState(); |
| 367 | } else { |
| 368 | this._content.texture = hiResItem.texture; |
| 369 | this._content.scale9Grid = hiResItem.scale9Grid |
| 370 | ? new Rectangle( |
| 371 | hiResItem.scale9Grid.x, |
| 372 | hiResItem.scale9Grid.y, |
| 373 | hiResItem.scale9Grid.width, |
| 374 | hiResItem.scale9Grid.height |
| 375 | ) |
| 376 | : null; |
| 377 | this._content.scaleByTile = hiResItem.scaleByTile || false; |
| 378 | this._content.tileGridIndice = hiResItem.tileGridIndice || 0; |
| 379 | this.sourceWidth = hiResItem.width; |
| 380 | this.sourceHeight = hiResItem.height; |
| 381 | this.updateLayout(); |
| 382 | } |
| 383 | } else if (hiResItem.type === EPackageItemType.MovieClip) { |
| 384 | this.sourceWidth = hiResItem.width; |
| 385 | this.sourceHeight = hiResItem.height; |
| 386 | this._content.interval = hiResItem.interval || 0; |
| 387 | this._content.swing = hiResItem.swing || false; |
| 388 | this._content.repeatDelay = hiResItem.repeatDelay || 0; |
| 389 | this._content.frames = hiResItem.frames || []; |
| 390 | this.updateLayout(); |
| 391 | } else if (hiResItem.type === EPackageItemType.Component) { |
| 392 | const obj = UIPackage.createObjectFromURL(itemURL); |
| 393 | if (!obj) { |
| 394 | this.setErrorState(); |
| 395 | } else if (!(obj instanceof GComponent)) { |
| 396 | obj.dispose(); |
| 397 | this.setErrorState(); |
| 398 | } else { |
| 399 | this._content2 = obj; |
| 400 | if (this._displayObject && this._content2.displayObject) { |
| 401 | this._displayObject.addChild(this._content2.displayObject); |
| 402 | } |
| 403 | this.updateLayout(); |
| 404 | } |
| 405 | } else { |
no test coverage detected