My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Copyright (c) 2008 - 2010 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.view {
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.utils.getDefinitionByName;
import flash.utils.*;
import flash.display.StageDisplayState;

import org.flowplayer.util.Arrange;
import org.flowplayer.util.Log;
import org.flowplayer.util.LogConfiguration;

public class Preloader extends MovieClip {
private var _log:Log = new Log(this);
private var _app:DisplayObject;
// this variable can be set from external SWF files, if it's set well use it to construct the config
public var injectedConfig:String;

public function Preloader() {

var logConfig:LogConfiguration = new LogConfiguration();
logConfig.level = "error";
logConfig.filter = "org.flowplayer.view.Preloader";
Log.configure(logConfig);
_log.debug("Preloader");

stop();
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}

private function onStageResize(e:Event):void{
setParentDimensions();
}

private function setParentDimensions():void{
if(stage.displayState == StageDisplayState.FULL_SCREEN || (Arrange.set && !Arrange.hasParent)){
Arrange.parentWidth=stage.stageWidth;
Arrange.parentHeight=stage.stageHeight;
return;
}
if(Arrange.set && Arrange.hasParent){
Arrange.parentWidth = Arrange.localWidth;
Arrange.parentHeight = Arrange.localHeight;
return;
}
var p:Object = parent;
while(p){
if(p.width !=0 && p.height !=0 && getQualifiedClassName(p) != 'mx.controls::SWFLoader'){
Arrange.parentWidth =Arrange.localWidth = p.width;
Arrange.parentHeight = Arrange.localHeight = p.height;
Arrange.hasParent = true;
break;
}
p=p.parent;
}
if(Arrange.parentWidth == 0 && Arrange.parentHeight == 0){
Arrange.parentWidth = stage.stageWidth;
Arrange.parentHeight = stage.stageHeight;
}
Arrange.set = true;
}

private function onAddedToStage(event:Event):void {
log("onAddedToStage(): stage size is " + Arrange.parentWidth + " x " + Arrange.parentHeight);
log("onAddedToStage(), bytes loaded " + loaderInfo.bytesLoaded);
stage.addEventListener(Event.RESIZE, onStageResize, false, 1);
setParentDimensions();

addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}

private function enterFrameHandler(evt:Event):void {
log("enterFrameHandler() " + loaderInfo.bytesLoaded);

if (loaderInfo.bytesLoaded == loaderInfo.bytesTotal) {
log("bytesLoaded == bytesTotal, stageWidth = " + Arrange.parentWidth + " , stageHeight = " + Arrange.parentHeight);
if (Arrange.parentWidth != 0 && Arrange.parentHeight != 0) {
initialize();
removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
}
}

private function initialize():void {
log("initialize()");
nextFrame();

if (_app) {
log("initialize(), _app already instantiated returning");
return;
}

prepareStage();
try {
var mainClass:Class = getAppClass();
_app = new mainClass() as DisplayObject;
addChild(_app as DisplayObject);
log("Launcher instantiated " + _app);
removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
} catch (e:Error) {
log("error instantiating Launcher " + e + ": " + e.message);
_app = null;
}
}

private function getAppClass():Class {
try {
return Class(getDefinitionByName("org.flowplayer.view.Launcher"));
} catch (e:Error) {
}
return null;
}

private function prepareStage():void {
if (! stage) return;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
}

private function log(msg:Object):void {
_log.debug(msg + "");
trace(msg + "");
}

private function get rotationEnabled():Boolean {
var config:Object = stage.loaderInfo.parameters["config"];
if (! config) return true;
if (config.replace(/\s/g, "").indexOf("buffering:null") > 0) return false;
return true;
}
}
}

Change log

r536 by StepanG on Aug 5, 2010   Diff
Changed the flowplayer logic to honor it's
parent's width and height. This means if
it is being loaded inside another swf,
flowplayer will have the dimensions of the
container it is being loaded into instead
of the stage.
Go to: 
Project members, sign in to write a code review

Older revisions

r449 by anssip on Apr 12, 2010   Diff
progress
r426 by anssip on Mar 25, 2010   Diff
reverted back to use the stage size
check
r425 by anssip on Mar 23, 2010   Diff
testing without stage size check
All revisions of this file

File info

Size: 5750 bytes, 153 lines
Powered by Google Project Hosting