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

This entry was posted in actionscript, bugs, flash and tagged , , , . Bookmark the permalink.