I've got a problem trying to apply a loading animation to my Flex application - a whole browser window occupant. I'm subclassing DownloadProgressBar class as described on Adobe's article about this. stageHeight
and stageWidth
, reported by base class are incorrect. It says 500x375 pixels in constructor and 0x0 elsewhere. Why?
我在尝试将加载动画应用到我的Flex应用程序时遇到了问题 - 整个浏览器窗口占用者。我正在按照Adobe关于此的文章所述继承DownloadProgressBar类。由基类报告的stageHeight和stageWidth不正确。它在构造函数中表示500x375像素,在其他地方表示0x0。为什么?
6 个解决方案
#1
Have you solved this problem? I have the same problem with my flex app. Stage returns 500x375. My workaround is not pretty. This function is called on FlexEvent.INIT_PROGRESS. So when my application is available i use its props.
你解决了这个问题吗?我的flex应用程序遇到了同样的问题。阶段返回500x375。我的解决方法并不漂亮。在FlexEvent.INIT_PROGRESS上调用此函数。因此,当我的应用程序可用时,我使用它的道具。
private function onFlexInitProgress( event:FlexEvent ):void {
if (Application.application != null){
var appWidth:Number = Application.application.width;
var appHeight:Number = Application.application.height;
x = (appWidth * 0.5) - (preloaderSWF.width * 0.5);
y = (appHeight * 0.5);
preloaderSWF.visible = true;
}
}
#2
i have code to center my custom progress loader and is working very much fine from this article http://askmeflash.com/article_m.php?p=article&id=7
我有代码来集中我的自定义进度加载器,并且从这篇文章非常好http://askmeflash.com/article_m.php?p=article&id=7
#3
I'm not sure if this will help but I think its possible to reference the size of the Flex application by using Application.width, Application.height.
我不确定这是否会有所帮助,但我认为可以通过使用Application.width,Application.height来引用Flex应用程序的大小。
http://livedocs.adobe.com/flex/3/html/help.html?content=app_container_2.html
The issues below seem to be related to your issue:
以下问题似乎与您的问题有关:
http://www.nabble.com/Stupid-Question---Flex-width-and-height-td21423345.html
http://www.nabble.com/Flex-stage-size-td20167125.html
http://dreamweaverforum.info/flex/125327-referencing-stage-flex.html
Hope they help.
希望他们帮忙。
#4
A width/height measurement of 0x0 is often indicative of the component in question not having been fully laid out at the time of the reading (including child components). Checking measurements in the constructor is surely too early. You'll want to check the measurements after you've set the stage to fullscreen and everything you're displaying has been laid out, probably at the applications creationComplete event, perhaps even later. The following link should be a good resource:
宽度/高度测量值0x0通常表示在读取时(包括子组件)未完全布局的组件。检查构造函数中的测量结果肯定太早了。在将舞台设置为全屏并且您正在显示的所有内容都已布局后,您可能需要检查测量值,可能是在应用程序creationComplete事件中,甚至可能更晚。以下链接应该是一个很好的资源:
http://blog.flexexamples.com/2007/08/07/creating-full-screen-flex-applications/
#5
What you want to do is add an event listener to the stage for its resize event and adjust the size of your preloader accordingly. Otherwise if someone resizes your Flex app while the preloader is displayed it will not resize.
你想要做的是为舞台上的resize事件添加一个事件监听器,并相应地调整预加载器的大小。否则,如果有人在显示预加载器时调整Flex应用程序的大小,则不会调整大小。
stage.addEventListener(Event.RESIZE, onStageResize);
public function onStageResize(e : Event) : void {
this.width = stage.stageWidth;
this.height = stage.stageHeight;
}
Or alternatively you can center your preloader on the stage using code like so:
或者您可以使用以下代码将预加载器置于舞台上:
preloader.x = this.stage.stageWidth/2 - preloader.width/2;
#6
I had this same problem in an actionscript project in flash builder, using 100% to 100% width and height. I observed that stage.stageWidth and stage.stageHeight was 500x375 until after the preloader had loaded the main class, then it would change to the full screen size. Because of this, the positioning of items in the preloader was incorrect. I discovered that it was this line in my main class that was getting the stage size to update:
我在flash builder中的actionscript项目中遇到了同样的问题,使用了100%到100%的宽度和高度。我观察到stage.stageWidth和stage.stageHeight是500x375,直到预加载器加载了主类后,它才会变为全屏大小。因此,预加载器中项目的定位不正确。我发现我的主类中的这一行正在更新阶段大小:
stage.scaleMode = StageScaleMode.NO_SCALE;
Here is how I implemented it in my preloader:
以下是我在预加载器中实现它的方法:
public function Preloader()
{
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(event:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
...
}
#1
Have you solved this problem? I have the same problem with my flex app. Stage returns 500x375. My workaround is not pretty. This function is called on FlexEvent.INIT_PROGRESS. So when my application is available i use its props.
你解决了这个问题吗?我的flex应用程序遇到了同样的问题。阶段返回500x375。我的解决方法并不漂亮。在FlexEvent.INIT_PROGRESS上调用此函数。因此,当我的应用程序可用时,我使用它的道具。
private function onFlexInitProgress( event:FlexEvent ):void {
if (Application.application != null){
var appWidth:Number = Application.application.width;
var appHeight:Number = Application.application.height;
x = (appWidth * 0.5) - (preloaderSWF.width * 0.5);
y = (appHeight * 0.5);
preloaderSWF.visible = true;
}
}
#2
i have code to center my custom progress loader and is working very much fine from this article http://askmeflash.com/article_m.php?p=article&id=7
我有代码来集中我的自定义进度加载器,并且从这篇文章非常好http://askmeflash.com/article_m.php?p=article&id=7
#3
I'm not sure if this will help but I think its possible to reference the size of the Flex application by using Application.width, Application.height.
我不确定这是否会有所帮助,但我认为可以通过使用Application.width,Application.height来引用Flex应用程序的大小。
http://livedocs.adobe.com/flex/3/html/help.html?content=app_container_2.html
The issues below seem to be related to your issue:
以下问题似乎与您的问题有关:
http://www.nabble.com/Stupid-Question---Flex-width-and-height-td21423345.html
http://www.nabble.com/Flex-stage-size-td20167125.html
http://dreamweaverforum.info/flex/125327-referencing-stage-flex.html
Hope they help.
希望他们帮忙。
#4
A width/height measurement of 0x0 is often indicative of the component in question not having been fully laid out at the time of the reading (including child components). Checking measurements in the constructor is surely too early. You'll want to check the measurements after you've set the stage to fullscreen and everything you're displaying has been laid out, probably at the applications creationComplete event, perhaps even later. The following link should be a good resource:
宽度/高度测量值0x0通常表示在读取时(包括子组件)未完全布局的组件。检查构造函数中的测量结果肯定太早了。在将舞台设置为全屏并且您正在显示的所有内容都已布局后,您可能需要检查测量值,可能是在应用程序creationComplete事件中,甚至可能更晚。以下链接应该是一个很好的资源:
http://blog.flexexamples.com/2007/08/07/creating-full-screen-flex-applications/
#5
What you want to do is add an event listener to the stage for its resize event and adjust the size of your preloader accordingly. Otherwise if someone resizes your Flex app while the preloader is displayed it will not resize.
你想要做的是为舞台上的resize事件添加一个事件监听器,并相应地调整预加载器的大小。否则,如果有人在显示预加载器时调整Flex应用程序的大小,则不会调整大小。
stage.addEventListener(Event.RESIZE, onStageResize);
public function onStageResize(e : Event) : void {
this.width = stage.stageWidth;
this.height = stage.stageHeight;
}
Or alternatively you can center your preloader on the stage using code like so:
或者您可以使用以下代码将预加载器置于舞台上:
preloader.x = this.stage.stageWidth/2 - preloader.width/2;
#6
I had this same problem in an actionscript project in flash builder, using 100% to 100% width and height. I observed that stage.stageWidth and stage.stageHeight was 500x375 until after the preloader had loaded the main class, then it would change to the full screen size. Because of this, the positioning of items in the preloader was incorrect. I discovered that it was this line in my main class that was getting the stage size to update:
我在flash builder中的actionscript项目中遇到了同样的问题,使用了100%到100%的宽度和高度。我观察到stage.stageWidth和stage.stageHeight是500x375,直到预加载器加载了主类后,它才会变为全屏大小。因此,预加载器中项目的定位不正确。我发现我的主类中的这一行正在更新阶段大小:
stage.scaleMode = StageScaleMode.NO_SCALE;
Here is how I implemented it in my preloader:
以下是我在预加载器中实现它的方法:
public function Preloader()
{
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(event:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
...
}