Flex IFrame 组件未在可视区域之外渲染
初学者问题: 我在 Flex 4 中使用 Flex 的 IFrame 组件。下面的代码在放置在滚动区域的顶部时有效。但是,如果我将其放在可视区域下方,它将不会渲染。我是 Flex 的完全初学者。有趣的是,当我在 HBox 处于视图中时调整窗口大小时,Iframe 将加载。但滚动到它不会。下面是我的代码。我已经确保一切都是可见的= true,但似乎我需要添加一个侦听器或以某种方式欺骗它认为窗口已调整大小以使其渲染。有人知道如何解决这个问题吗?谢谢!
<mx:HBox visible="true" backgroundColor="#cccccc" id="facebookhbox" width="100%" height="100" horizontalAlign="center" verticalAlign="middle" verticalGap="0" verticalScrollPolicy="off">
<mx:Canvas id="facebookcanvas" visible="true" x="0" y="0" width="650" height="80">
<flexiframe:IFrame visible="true" y="0" x="0" id="facebookIFrame" source="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.examplelink.com&layout=standard&show_faces=true&width=450&action=like&colorscheme=light&height=80" width="450" height="80"/>
</mx:Canvas>
</mx:HBox>
Beginner Question:
I am using the IFrame Component for Flex in Flex 4. The code below works when it is put at the top of the scrolling area. However, if I put it where it below the viewable area it will not render. I am a complete beginner to Flex. The interesting thing is when I resize the window while the HBox is in view, the Iframe will load. But scrolling to it will not. Below is my code. I have made sure everything is visible=true but it seems like I need to add a listener or somehow trick it to think that the window has been resized to get it to render. Anyone with an idea how to fix this? Thanks!
<mx:HBox visible="true" backgroundColor="#cccccc" id="facebookhbox" width="100%" height="100" horizontalAlign="center" verticalAlign="middle" verticalGap="0" verticalScrollPolicy="off">
<mx:Canvas id="facebookcanvas" visible="true" x="0" y="0" width="650" height="80">
<flexiframe:IFrame visible="true" y="0" x="0" id="facebookIFrame" source="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.examplelink.com&layout=standard&show_faces=true&width=450&action=like&colorscheme=light&height=80" width="450" height="80"/>
</mx:Canvas>
</mx:HBox>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有使用 Flex IFrame 的经验,仅供参考,但一般来说,您可以使组件的大小无效或使显示列表无效,然后立即调用验证以强制 LayoutManager 重新计算元素及其子元素的大小(或者简单地绘制在使显示列表无效的情况下):
我在这里看到的困难部分是弄清楚您到底希望什么时候发生(即从滚动条捕获某种事件)。出于测试目的,您可以创建一个按钮,并在其单击处理程序中执行以下操作:
如果成功,那么您只需要从 Scroller 或 Canvas 中找到适当的事件,告诉您何时发生滚动(最坏的情况下您可以捕获鼠标)向下标记一个标志,然后捕获 mouseMove,如果设置了该标志,则运行代码以使其无效/重新验证)。基本上,布局/绘图的工作原理是 UIComponent 有标志,让其知道何时需要重新计算某些内容的大小或重新绘制它,这样,所有内容并不总是只重绘那些需要它的组件。在这种情况下,FacebookIFrame 似乎并没有在应该失效的时候失效。如果我还可以提供帮助或者这不起作用,请告诉我。
更新以包含显示示例工作的完整应用程序,这绝不是一种好方法,这是由于 IFrame 代码中的错误应该修复(尽管我不确定该错误如何存在或在哪里存在)某些东西应该会导致它在没有的情况下适当地失效)。
肖恩
No experience with the Flex IFrame here just FYI but in generic terms you can invalidate the size of the component or invalidate the display list then call validate now in order to force the LayoutManager to recalculate the sizes of the element and it's children (or simply draw in the case of invalidating the display list):
The difficult part I see here is figuring out when exactly you want that to happen (that is capturing some sort of event from the scrollbar). For test purposes you can just create a button and in it's click handler do the following:
If this works out then you just need to find the appropriate event from the Scroller or Canvas that tells you when scrolling is occuring (at worst you could capture mouse down mark a flag then capture mouseMove and if the flag is set then run the code to invalidate/re-validate). Basically how the layout/drawing works is that the UIComponents have flags that let it know when it needs to recalculate the size of something or redraw it, this way everything isn't always redrawn only those components that require it. In this case it seems the FacebookIFrame isn't getting invalidated at some point when it should. Let me know if I can help anymore or if this doesn't work out.
Updated to include a full application showing the example working, this is by no means a good way of doing things, this is due to a bug in the IFrame code that should be fixed (though I'm not sure how or where the bug exists something should be causing it to invalidate appropriately where it is not).
Shaun