禁用 Flex CSS 类型选择器警告?

发布于 2024-08-06 10:52:55 字数 1233 浏览 2 评论 0原文

我正在构建一个相当大的 Flex 项目,其中包含多个模块(生成多个 SWF 的单个 Flex 项目)

现在,我有一个 css 文件,正在加载到主 SWF 标记中:

<s:Application ... >
    <fx:Style source="css/main.css" />
...
</s:Application>

在 CSS 文件中:

/* CSS file */
@namespace s "library://ns.adobe.com/flex/spark";

s|Panel { 
    skinClass: ClassReference("com.skins.DefaultPanelSkin"); 
} 

s|Button {
    skinClass: ClassReference("com.skins.DefaultButtonSkin");
}

CSS 文件是没有在其他地方引用。

我目前有6个模块(加上主SWF,总共7个SWF)。我注意到警告的数量与模块的数量相关......每次添加模块时,我都会收到更多警告。现在,我对 CSS 文件中的每个条目都收到 6 个警告,因此:

CSS type selectors are not supported in components: 'Panel'
CSS type selectors are not supported in components: 'Panel'
CSS type selectors are not supported in components: 'Panel'
CSS type selectors are not supported in components: 'Panel'
CSS type selectors are not supported in components: 'Panel'
CSS type selectors are not supported in components: 'Panel'

对 Button、TextArea 等重复。我有很多无用的警告,无法查看是否有任何有效的警告。

这个警告是由我做错了什么引起的吗?这些样式都已正确应用,并且在运行时似乎按照我想要的方式工作。如果我没有做错什么,我可以告诉编译器忽略这个警告吗?

注意:我已经尝试过 -show-unused-type-selector-warnings=false 编译器标志,但它不起作用......这是一个类似但不同的警告。

I'm building a somewhat large Flex project that includes several modules (a single Flex project that produces multiple SWFs)

Right now, I have a single css file, being loaded in the main SWF tag:

<s:Application ... >
    <fx:Style source="css/main.css" />
...
</s:Application>

In the CSS file:

/* CSS file */
@namespace s "library://ns.adobe.com/flex/spark";

s|Panel { 
    skinClass: ClassReference("com.skins.DefaultPanelSkin"); 
} 

s|Button {
    skinClass: ClassReference("com.skins.DefaultButtonSkin");
}

The CSS file is not referenced anywhere else.

I have currently 6 modules (plus the main SWF, a total of 7 SWFs). I've noticed that the number of warnings is correlated to the number of modules...every time I add a module, I get more warnings. Right now, I get 6 warnings for every entry in the CSS file, so:

CSS type selectors are not supported in components: 'Panel'
CSS type selectors are not supported in components: 'Panel'
CSS type selectors are not supported in components: 'Panel'
CSS type selectors are not supported in components: 'Panel'
CSS type selectors are not supported in components: 'Panel'
CSS type selectors are not supported in components: 'Panel'

And repeat for Button, TextArea, etc etc. I have so many useless warnings, it is impossible to see if there are any valid ones.

Is this warning caused by something I'm doing wrong? The styles are all being applied correctly and appears to work just the way I want at runtime. If I'm doing nothing wrong, can I tell the compiler to ignore this warning?

NOTE: I've tried the -show-unused-type-selector-warnings=false compiler flag, and it does not work...that's for a similar but different warning.

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

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

发布评论

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

评论(7

梦回旧景 2024-08-13 10:52:55

如果您正在查看 FlexBuilder 中的警告,您应该能够使用 Eclipse 的问题过滤 GUI。假设 Flex 4 在这方面与 Flex 3 非常相似,那么在右上角的问题标签上,有一个带有工具提示的按钮“配置要应用于此视图的过滤器”。就是那个带箭头的。

在过滤器对话框中的默认过滤器上,将说明设置为“不包含”,并将其下方的文本设置为“组件中不支持 CSS 类型选择器”。

If you're looking at the warnings in FlexBuilder, you should be able to use Eclipse's problem filtering GUI. Assuming Flex 4 is sufficiently similar to Flex 3 in this regard, on the problems tag at the top right, there's a button with the tooltip "Configure the filters to be applied to this view". It's the one with the arrows.

In the filters dialog, on the default filter, set description to "doesn't contain" and the text under it to "CSS type selectors are not supported in components".

紧拥背影 2024-08-13 10:52:55

所以我最终只是将源代码下载到编译器,搜索它以找到该警告,将其注释掉,然后重新编译编译器。这与标记为gumbo beta2 的版本相反。

Index: modules/compiler/src/java/flex2/compiler/css/StylesContainer.java
===================================================================
--- modules/compiler/src/java/flex2/compiler/css/StylesContainer.java   (revision 10941)
+++ modules/compiler/src/java/flex2/compiler/css/StylesContainer.java   (working copy)
@@ -198,11 +198,11 @@
         {
             // [preilly] This restriction should be removed once the
             // app model supports encapsulation of CSS styles.
-            ComponentTypeSelectorsNotSupported componentTypeSelectorsNotSupported =
+            /*ComponentTypeSelectorsNotSupported componentTypeSelectorsNotSupported =
                 new ComponentTypeSelectorsNotSupported(getSource().getName(),
                                                        lineNumber,
                                                        selector);
-            ThreadLocalToolkit.log(componentTypeSelectorsNotSupported);
+            ThreadLocalToolkit.log(componentTypeSelectorsNotSupported);*/
             return true;
         }

这不是最优雅的解决方案......但这些警告真的很烦人。

So I ended up just downloading the source to the compiler, searching through it to find that warning, commented it out, and re-compiled the compiler. This is against the version tagged for gumbo beta2.

Index: modules/compiler/src/java/flex2/compiler/css/StylesContainer.java
===================================================================
--- modules/compiler/src/java/flex2/compiler/css/StylesContainer.java   (revision 10941)
+++ modules/compiler/src/java/flex2/compiler/css/StylesContainer.java   (working copy)
@@ -198,11 +198,11 @@
         {
             // [preilly] This restriction should be removed once the
             // app model supports encapsulation of CSS styles.
-            ComponentTypeSelectorsNotSupported componentTypeSelectorsNotSupported =
+            /*ComponentTypeSelectorsNotSupported componentTypeSelectorsNotSupported =
                 new ComponentTypeSelectorsNotSupported(getSource().getName(),
                                                        lineNumber,
                                                        selector);
-            ThreadLocalToolkit.log(componentTypeSelectorsNotSupported);
+            ThreadLocalToolkit.log(componentTypeSelectorsNotSupported);*/
             return true;
         }

Not the most elegant solution...but those warnings were really getting annoying.

仅此而已 2024-08-13 10:52:55

我发现此警告的另一个原因是当您从类中引用parentApplication 时。

我的项目有 2 个应用程序,在很多情况下,我出于某种原因需要访问其中一个应用程序。

如果我按如下方式引用我的parentApplication,我会看到警告:

(this.parentApplication as SomeAppName).someFunction();

如果我保留通用引用,错误就会消失:

this.parentApplication.someFunction();

这并不是要评论这是否是一个好的做法,而是希望帮助一些人找到一个根本原因。

One other cause I have found for this warning is in the case when you reference the parentApplication from within a class.

My project has 2 apps, and there are several cases when I needed to reach into one or the other of the applications for one reason or other.

If I reference my parentApplication as follows, I see the warnings:

(this.parentApplication as SomeAppName).someFunction();

If I leave the reference general, the errors go away:

this.parentApplication.someFunction();

This is not meant to comment on whether or not this is good practice, but it is to hopefully help some folks find a root cause.

hth

深海蓝天 2024-08-13 10:52:55

问题是您无法在加载的模块中定义全局样式。您可以为 Module 标记使用特定的样式名称,并在 css 中使用后代将样式应用到子组件:

<mx:Module styleName='mySubStyle' .../>

并在 css 中使用:

.mySubStyle s|Panel { color: #FF0000; }

The problem is that you cannot define global styles in loaded modules. You can use a specific stylename for the Module tag and use descendant in your css to apply the styles to the sub components:

<mx:Module styleName='mySubStyle' .../>

and in the css use:

.mySubStyle s|Panel { color: #FF0000; }
时光匆匆的小流年 2024-08-13 10:52:55

看来您需要为 CSS 命名空间:来自 文档:“未通过名称空间限定的类型选择器或未解析为链接到应用程序的 ActionScript 类的类型选择器会在编译时导致警告。”

他们给出的示例是:

<Style>
    @namespace "library://ns.adobe.com/flex/spark";
    @namespace cx "com.mycompany.*";

    Button { color: #990000; }
    cx|MyFancyButton { color: #000099; }
</Style>

从您的示例来看,您似乎缺少自定义名称空间,并且由于您的体系结构是模块化的,因此这些类在编译时不会解析为应用程序。

It looks as though you need to namespace your CSS: from the documentation: "Type selectors that are either not qualified by a namespace or do not resolve to an ActionScript class linked into the Application cause a warning at compile time."

The example they give is:

<Style>
    @namespace "library://ns.adobe.com/flex/spark";
    @namespace cx "com.mycompany.*";

    Button { color: #990000; }
    cx|MyFancyButton { color: #000099; }
</Style>

From your example, you seem to be missing the custom namespace, and, since your architecture is modular, the classes don't resolve to the application at compile time.

剩余の解释 2024-08-13 10:52:55

将其添加到项目属性中的编译器标志中:

-show-unused-type-selector-warnings=false

Add this to compiler flags in project properties:

-show-unused-type-selector-warnings=false
谎言 2024-08-13 10:52:55

如果仍然有这些警告,您能否检查一下是否已将其中一个组件标记为要构建为应用程序?

这些“不正确”的 CSS 类型选择器警告出现在我的一个项目中。我注意到 Flex Builder 为我的一个组件创建了一个额外的应用程序(您可以在 bin-debug 文件夹中检查它)。当我将组件作为应用程序删除后,警告就消失了。

请注意,组件中没有 css 声明,并且警告出现在我的主应用程序资源中。

您可以删除组件的“构建为应用程序”标记,方法是转到应用程序的属性面板,打开Flex应用程序选项卡,选择组件并单击“删除”按钮。

作为额外的好处,编译时间减少了(至少快了 5 倍)。

If you still have these warnings, can you check if you have marked one of your components to be build as an application?

Those 'incorrect' css type selector warnings showed up in one of my projects. I noticed that Flex Builder made an extra application for one of my components (you can check this in your bin-debug folder). As soon as I removed the component as an application, the warnings went away.

Note that there was no css declaration in the component, and the warnings showed up at my main application resource.

You can remove the 'build as an application' mark for a component by going to the properties panel of your application, open the Flex Application tab, select the component and click the 'remove' button.

As an extra bonus, the compilation time decreased (at least 5 times faster).

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