The parseCSS of StyleSheet silently fails

Hi,

when you use the parseCSS method of the StyleSheet, you will have no indication about success of the invocation. When passed string contains invalid CSS text then this method will silently fails. The workaround is to compare the lenght of the styleNames property before and after the call to parseCSS, if both values are equal then parseCSS has failed.

		protected function parseCss(stylesheet:StyleSheet, cssText:String):Boolean
		{
			if (!stylesheet)
			{
				Log.f(TAG, "Invalid argument, stylesheet can't be null.");
				return false;
			}
			if (!cssText || cssText == "")
			{
				Log.f(TAG, "Invalid argument, cssText can't be null nor empty.");
				return false;
			}
			
			var _nStylesLength:int = stylesheet.styleNames.length;
				
				stylesheet.parseCSS(cssText);
				
				
				if (_nStylesLength == stylesheet.styleNames.length)
				{
					Log.f(TAG, "There has been an error while parsing css string.");
				}
				
			return _nStylesLength != stylesheet.styleNames.length;
		}

best regards

StyleSheet’s method getStyle doesn’t return null for non-existing style

I have just learned that getStyle() method of flash.text.StyleSheet class doesn’t return null value when requested style doesn’t exists. Documentation states that it should, but in fact it returns empty object. Which could be fine for tests but you could have a style with empty declaration block which would create false positive result. This error appears to be for some time, check screen grabs from different players starting from fp9.
Continue reading