Jump to content
GreenSock

icekomo

error while loading css

Recommended Posts

Any idea why this line of code here:

queue.append( new CSSLoader("xml/styles/styles.css", {name:"myCSS",onProgress:progressHandler}) );

 

would throw this error?

TypeError: Error #1034: Type Coercion failed: cannot convert flash.text::StyleSheet@261fd699 to XML.

 

If I comment this out, it works fine, but I'm trying to get a style sheet loaded into this project.

 

Thanks!

Link to comment
Share on other sites

It sounds like there must be something else in your code that is causing the error - are you trying to cast the content to XML somewhere? Maybe in the onComplete handler of your queue? If you're still running into trouble, please create a simple FLA that demonstrates the problem and post it here along with a css file that your FLA is loading so that we can just publish the FLA and see the error for ourselves.

Link to comment
Share on other sites

So after more looking into it I think my problem lies here:

 

var cssData:StyleSheet = LoaderMax.getContent("myCSS");

var sheet:StyleSheet = new StyleSheet();

sheet.parseCSS(cssData.data);

trace(cssData.data);

//trace("css loaded");

brunchMenu.Menu_mc.content_mc.menuTxt.styleSheet = sheet;

 

As I am not sure how to attach the stylesheet to my text field once loaded....any help would be grateful!

 

Thanks

Link to comment
Share on other sites

The content of a CSSLoader is a StyleSheet - it looks like you're duplicating a bunch of functionality (parsing parsed content). I believe it would be as simple as:

 

brunchMenu.Menu_mc.content_mc.menuTxt.styleSheet = LoaderMax.getContent("myCSS");

Link to comment
Share on other sites

That didn't seem to work.

 

WIth the xml data I had to do this:

 

var xmlData:XML = LoaderMax.getContent("myXML");

brunchMenu.Menu_mc.content_mc.menuTxt.htmlText = xmlData.Brunch;

 

I had to type case the data into xml for it to be able to use it, do I have to do something similar with the css data?

 

Thanks for you help on this!

Link to comment
Share on other sites

Nope, you shouldn't have to cast it in this case. A CSSLoader's "content" will already be a StyleSheet, so I'm not sure why it's not working for you - feel free to post a very simple example FLA that we can publish and see the error for ourselves.

Link to comment
Share on other sites

Here is the preloader code that I am using:

I altered it a bit so that I have a simple textfield on the stage(myTextField) and gets filled with some xml, and I am trying to apply a style sheet to that, figure start small and go from there, but even thats not working, I get the xml to show up, but it's not styled.

 

package com.main

{

import flash.display.*;

import com.greensock.events.LoaderEvent;

import flash.events.*;

import flash.display.MovieClip;

import flash.text.TextField;

import flash.text.StyleSheet;

import flash.events.Event;

import com.greensock.easing.*;

import com.greensock.*;

import com.greensock.plugins.*;

import com.greensock.layout.*;

import com.greensock.loading.*;

import com.greensock.loading.display.*;

 

public class Preloader extends MovieClip

{

var queue:LoaderMax = new LoaderMax({name:"mainQueue",onComplete:completeHandler,onError:errorHandler});

var progressBar:MovieClip = new progBar_mc();

 

public function Preloader()

{

addChild(progressBar);

//starts the load for the XML

queue.append( new XMLLoader("xml/elReyMenus.xml", {name:"myXML",onProgress:progressHandler,onComplete:loadXml}) );

queue.append( new CSSLoader("xml/styles/styles.css", {name:"myCSS",onProgress:progressHandler}) );

//starts the load for the swf file, and adds it to this container

queue.append( new SWFLoader("elRey.swf", {onProgress:progressHandler,estimatedBytes:126000,container:this}) );

//loads the data

queue.load();

progressBar.loadText.text = "loading xml";

}

 

public function loadXml(event:LoaderEvent):void

{

progressBar.loadText.text = "loading data";

}

 

public function progressHandler(event:LoaderEvent):void

{

//trace("progress: " + event.target.progress);

var perc:Number = event.target.bytesLoaded / event.target.bytesTotal;

progressBar.prog_txt.text = Math.ceil(perc * 100) + "%".toString();

progressBar.loadBar_mc.width = perc * 271;

}

 

public function completeHandler(event:LoaderEvent):void

{

var xmlData:XML = LoaderMax.getContent("myXML");

myTextField.htmlText = xmlData.Brunch;

myTextField.styleSheet = LoaderMax.getContent("myCSS");

trace(event.target + " is complete!");

TweenLite.to(progressBar,2,{alpha:0});

}

 

public function errorHandler(event:LoaderEvent):void

{

trace("error occured with " + event.target + ": " + event.text);

}

}

}

CSS:

boldtitle

{

font-weight: bold;

display: inline;

font-size: 16px;

}

boldText

{

font-weight: bold;

display: inline;

}

smallText{

display: inline;

font-size: 11px;

}

 

XML:

</p><p>&nbsp;</p><p><boldtitle>Soft Drinks</boldtitle></p><p>&nbsp;</p><p><boldText>Agua Frescas</boldText></p><p>Tamarindo</p><p>Jamaica</p><p>Horchata</p><p>&nbsp;</p><p><boldText>Jarritos</boldText></p><p>Pineapple</p><p>Grapefruit</p><p>Mandarin</p><p>&nbsp;</p><p><boldText>Refrescos</boldText></p><p>Sidral Mundet Apple Soda</p><p>Mexican Coca-cola</p><p>

Link to comment
Share on other sites

I should also say, that I'm not getting any error any more, but the text is not being styled either....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×