Flex>最佳实践?

发布于 2024-10-01 10:16:52 字数 241 浏览 3 评论 0原文

只是想问一下使用 as 包含时该怎么做(即

问题是在我的所有文件中,我'我使用仅限类的修饰符,例如 private、public protected 和 FB,有时会对此提出抗议,一位朋友告诉我,他所做的是将文件扩展名更改为 .ias,但这样,他就失去了代码突出显示、内容 -协助并启用断点

Just wanted to ask about what to do when using as includes (ie <fx:Script source="includes/my_as3_file.as" />.

The problem is that in all of my files I'm using class-only modifiers, such as private, public protected, and FB sometimes protests regarding these. A friend told me that what he does is changing the file extension to .ias, but in this way, he loses code highlighting, content-assist and enabling breakpoints.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

赠意 2024-10-08 10:16:52

我喜欢使用名为 ViewHelper 的东西(发布了链接)

http://www.kensodev.com/2010/08/19/keep-your-mxml-files-neat-with-view-helpers/

这样,MXML 文件就是始终是纯 MXML,并且视图助手是耦合的并且具有对视图的引用,这意味着您可以在视图助手中执行类似的操作

myView.dataGrid.visible = false;

,当然还有更多的事情。

即使当我使用 RobotLegs 的中介器时,我仍然使用视图助手来执行与视图相关的所有操作,例如动画、隐藏和固定物体、状态更改等。我仅使用中介器来与 RobotLegs 框架进行中介(重新调度事件)并监听 eventDispatcher。

I like to use something called a ViewHelper (posted a link)

http://www.kensodev.com/2010/08/19/keep-your-mxml-files-neat-with-view-helpers/

This way, the MXML file is pure MXML at all times, and the view helper is coupled and has a reference to the view meaning you can do something like this in your view helper

myView.dataGrid.visible = false;

And of course many more things.

Even when I use RobotLegs's mediators, I still use the view helper for all actions that concern the view such as animations, hiding and shoeing things, state changing and more. I use the mediators only to mediate with the RobotLegs framework (re-dispatch events) and listen to the eventDispatcher.

醉梦枕江山 2024-10-08 10:16:52

就我个人而言,我不喜欢使用 include。正如您所提到的,它往往会混淆视图中实际发生的情况,并且使得快速扫描文件并了解其行为变得困难。

我一直遵循的最佳实践之一是将 块中的代码量减少到几乎没有。

如果您使用的是包含文件,这表明您的视图中的脚本非常多,这可能会导致代码重用不良,并且难以编写可测试的代码。

相反,请考虑使用演示模型模式,将逻辑移出到一个单独的类。或者,还有中介器 模式,但我个人发现这会导致耦合程度更高的代码 - 尽管这可能是由于我糟糕的执行,而不是模式的失败。

Personally, I'm not a fan of using includes. As you've mentioned, it tends to obfuscate what's actually going on within a view, and makes it difficult to quickly scan a file and grok it's behaviour.

One of the best practices I've always followed is to reduce the amount of code within an <fx: Script /> block to almost none.

If you are using an include file, this suggests that your views are very script-heavy, which can lead to poor code reuse, and difficulty in writing testable code.

Instead, consider using the Presentation Model pattern where the logic is moved out to a separate class. Alternatively, there's also the Mediator pattern, however personally I've found this leads to more heavily coupled code - though that's likely down to my crappy execution, than a failing of the pattern.

猫腻 2024-10-08 10:16:52
  1. 使用后面的代码!
  2. [mxml_file]AS.as 作为 Actionscript 文件名。
    ex MXML:MyView.mxml 和 as 文件 MyViewAS.as
    那么它看起来像
  1. Use code behind!
    or
  2. [mxml_file]AS.as for Actionscript file name.
    ex MXML: MyView.mxml and the as file MyViewAS.as
    then it will look like <fx:Script source="MyViewAS.as" />
酒绊 2024-10-08 10:16:52

在我看来,将 .as 文件重命名为 .ias 是人们能想到的最糟糕的解决方案之一(这太可怕了)。我也有点不同意 Marty 的观点,因为在 Flex 4 中,架构与 Flex 3 不同(尽管 Spark 是构建在 MX 之上的 - 如果我们谈论的是 Flex 3,那么我会同意 Marty 所说的)。在 Flex 4 中,皮肤现在被认为是“视图”,而使用视图的类是“控制器”...这意味着现在的事物比在 Flex 3 中分离得更好,在 Flex 3 中,组件有点发挥作用视图和控制器的角色 ( http://www.slideshare.net/ saurabhnarula/flex-4-skinning-2634949)。

回到最初的问题:Flash Builder 确实并不完美,但如果您知道代码中没有任何错误并且它不断向您抛出一些奇怪的东西,那么只需尝试关闭它并启动它再次(之后清理您的项目)。每当我将 .as 文件设置为 MXML 组件的源时,我喜欢将该文件放在 MXML 类旁边(例如:MyMXMLComponent.mxml 和 MyMXMLComponentAS.as,两者都处于同一级别 - source="MyMXMLComponentAS.AS ”)。这 99% 的时间都工作正常,但实际上很少,我可能还会从 Flash Builder 收到一些奇怪的错误(通常通过关闭它并随后清理项目来解决 - 有几次,实际上存在错误我的代码似乎完全混淆/崩溃了编译器,并使其抛出一些非常无意义的错误消息,所以一定要尝试确保您的代码是正确的)。

就我个人而言,我建议您不要使用 .as 文件,而是尝试使用“代码隐藏”方法(在 Google / Adob​​e 上搜索有关此内容的更多信息 - 我想发布一个链接,但由于我是新人用户,我仅限于 1 个链接/帖子...哈哈)。使用代码隐藏,您肯定永远不会遇到使用 .as 文件可能遇到的问题,并且您肯定永远不会遇到代码提示问题。如果您以前从未使用过代码隐藏,那么一开始可能会感觉“奇怪”,但您会习惯它,并且您肯定不想再次“以旧方式”编写代码。

Renaming the .as file to .ias, in my opinion, is one of the worst solutions one can come up with ( it's just horrible ). I also kinda disagree with Marty, because in Flex 4, the architecture is different from Flex 3 ( although Spark is built on top of MX - if we were talking about Flex 3, then I'd agree with what Marty said ). In Flex 4, the Skin is now considered to be the "View" and class making use of the view is the "Controller"... meaning that things are now much better separated than they were in Flex 3, where a components kinda played the role of both the View and Controller ( http://www.slideshare.net/saurabhnarula/flex-4-skinning-2634949 ).

Coming back to the original problem: It's true that Flash Builder is not perfect, but if you know that you don't have any errors in your code and it keeps on throwing some weird stuff at you, then simply try closing it and starting it again ( Clean your project afterward ). Whenever I set an .as file as the source for my MXML component, I like to have the file next to the MXML class ( ex: MyMXMLComponent.mxml and MyMXMLComponentAS.as, both being at the same level - source="MyMXMLComponentAS.AS" ). This 99% of the time works fine, but really rarely, I might have also received some weird errors from Flash Builder ( which usually got solved by closing it and cleaning the project afterward - on a couple of occasions, there was actually an error in my code which seemed to totally confuse/crash the compiler and make it throw some really senseless error messages, so definitely try to make sure that your code is correct ).

Personally, I'd suggest that instead of using .as files, you try to use the "code behind" approach ( search on Google / Adobe for more info on this - I wanted to post a link, but since I'm a new user, I'm limited to 1 link / post... hah ). Using code behind, you will surely never run into the problems you might run into with .as file and you will surely never have problems with code hinting. In case you have never used code behind before, then it might feel "strange" at the beginning, but you'll get used to it and you'll surely not want to write code "the old way" ever again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文