AS3 Twitter feeds δυσκολίες...

ActionScript και Flex Προγραμματισμός

Συντονιστές: WebDev Moderators, Super-Moderators

Απάντηση
Foenix1984
Δημοσιεύσεις: 1
Εγγραφή: 11 Ιουν 2010 21:22
Επικοινωνία:

AS3 Twitter feeds δυσκολίες...

Δημοσίευση από Foenix1984 » 11 Ιουν 2010 21:49

Γεια σας
Φτιάχνω μιά ιστοσελίδα οπού θέτοντας μιά λέξη ώς keyword (πχ για παράδειγμα teenage boy) ενεργοποιώ μια λειτουργία πού κάνει fetch feeds από to Twitter με την συγκεκριμένη keyword λεξη. Εχω όμως μερικά προβλήματα πού ακόμα δέν έχω λύσει.

1) Θέλω κάθε φορά τό κείμενο νά εμφανιζ'εται μέσα σε quotation marks ("....").Υποθέτω πώς θα γίνεται με regular expressions αλλά ακόμα δέν έχω βρεί λυση.

2)Πώς μπορώ να κάνω apply CSS style στο Dynamic text.

3) Μερικές φορές δέν μού επιστρέφει καθόλου αποτελέσματα...τι μπορώ να κάνω γιαυτό?

Αυτές είναι όι πίο σημαντικές δυσκολίες μού.

Κάθε βοήθεια καλοδεχούμενη

Σας Ευχαριστώ

P.S Εδω ειναι ο κωδικας οπου box = button και replace_txt = dynamic text

Κώδικας: Επιλογή όλων

var lyricsLength:Number = 250;//Trim lyrics to a max number of characters
var maxClips:Number = 1;//Maximum number of entries to extract from each feed
var clips:Sprite = new Sprite();//Container for all text clips
addChildAt(clips, 1);
var query_txt:String ;
box.buttonMode = true;
box.addEventListener( MouseEvent.CLICK, function( e:Event ):void { query_txt = "teenage boy"; loadFeeds(e); });
var query:String;
box.addEventListener(MouseEvent.MOUSE_OVER, onOver);
box.addEventListener(MouseEvent.MOUSE_OUT, onOut);
function onOver(e:MouseEvent):void
{
   e.currentTarget.gotoAndPlay("over");
}
function onOut(e:MouseEvent):void
{
   e.currentTarget.gotoAndPlay("out");
}
box.addEventListener(MouseEvent.CLICK , playS);
function playS(e:MouseEvent):void
{
   e.currentTarget.gotoAndStop("click");
}

function loadFeeds(evt:Event):void{
   query = query_txt != "" ? query_txt: "";
   var feedUrls:Array = [
            "http://search.twitter.com/search.atom?lang=en&q="+query, // TWITTER FEEDS
            //"http://api.lyricsfly.com/api/txt-api.php?i=" + lyricsflyTempId + "&l="+query // LYRICS FEEDS
            ];
   for( var index:String in feedUrls ) {
      var feedLoader:URLLoader = new URLLoader();
      var feedURL:URLRequest = new URLRequest(feedUrls[index]);
      feedLoader.addEventListener(Event.COMPLETE, feedLoaded);
      feedLoader.load(feedURL);
   }
}
function feedLoaded(evt:Event):void {
   
   var feedXML:XML = new XML();
   feedXML.ignoreWhitespace = true;
   feedXML = new XML(evt.target.data);
   feedXML = removeNS(feedXML);
   var index:String;
   trace( feedXML.toXMLString() ); //Uncomment to see XML
   if( feedXML ){
      //Is it rss?
      if( feedXML.channel ){
         for(index in feedXML.channel.item) {
            if&#40; int&#40; index &#41; < maxClips &#41; replace_txt.text=feedXML.channel.item&#91;index&#93;.title;
            //DATE - feedXML.channel.item&#91;item&#93;.pubDate.substr&#40;0, 16&#41;
         &#125;
      &#125;
      //Is it atom?
      if&#40; feedXML.entry &#41;&#123;
         for&#40;index in feedXML.entry&#41; &#123;
            if&#40; int&#40; index &#41; < maxClips &#41; replace_txt.text=feedXML.entry&#91;index&#93;.published.substr&#40;0, 0&#41; /* HERE WE ADD &#58;+ ' &#58; '*/+ feedXML.entry&#91;index&#93;.published.substr&#40;0,0&#41; /* HERE WE ADD &#58;+ ' &#58; ' */ + feedXML.entry&#91;index&#93;.title;
            //DATE - feedXML.entry&#91;entry&#93;.published.substr&#40;0, 10&#41;
         &#125;
      &#125;
      //Is it lyricsfly? - non standard xml format!
      if&#40; feedXML.sg &#41;&#123;
         var lineBreakPattern = /\&#91;br\&#93;/g; // match &#91;br&#93; to be replaced with \n &#40;flash newline&#41;
         var commentsPattern = /\&#91;&#91;^\&#93;&#93;*\&#93;/g; // lyrics have comments in them!!!
         
         for&#40;index in feedXML.sg&#41; &#123;
            //trace&#40; feedXML.sg&#91;index&#93;.tx.indexOf&#40;query,0&#41; &#41;;
            if&#40; int&#40; index &#41; < maxClips &#41; replace_txt.text=feedXML.sg&#91;index&#93;.tx.substr&#40; 0, lyricsLength &#41;.replace&#40;lineBreakPattern,"\n"&#41;.replace&#40;commentsPattern,""&#41;;
         &#125;
      &#125;
      
   &#125;
&#125;
///////REMOVE REGULAR EXPRESSIONS

function removeNS&#40;fXML&#58;XML&#41;&#123;
        var xmlString = fXML.toXMLString&#40;&#41;;
        var xmlnsPattern = new RegExp&#40;"xmlns&#91;^\"&#93;*\"&#91;^\"&#93;*\"", "gi"&#41;;
        var namespaceRemovedXML = xmlString.replace&#40;xmlnsPattern, ""&#41;;

        var aaaPattern = new RegExp&#40;"aaa&#58;lang&#91;^\"&#93;*\"&#91;^\"&#93;*\"", "gi"&#41;;
        var aaaRemovedXML = namespaceRemovedXML.replace&#40;aaaPattern, ""&#41;;

        var twitterPattern = new RegExp&#40;"twitter&#58;", "gi"&#41;;
        var twitterRemovedXML = aaaRemovedXML.replace&#40;twitterPattern,""&#41;;
       
        var geoPattern = new RegExp&#40;"georss&#58;", "gi"&#41;;
        var geoRemovedXML = twitterRemovedXML.replace&#40;geoPattern,""&#41;;
       
        var openSearchPattern = new RegExp&#40;"openSearch&#58;", "gi"&#41;;
        var openSearchRemovedXML = geoRemovedXML.replace&#40;openSearchPattern,""&#41;;

        var lyricsflyPattern = new RegExp&#40;"*** Your access is restricted to30% of content. Please get permanent user ID key for 100% atlyricsfly.com/api/ *** &#91;br&#93; Lyrics delivered by lyricsfly.com", "gi"&#41;;
        var lyricsflyRemovedXML =openSearchRemovedXML.replace&#40;lyricsflyPattern,""&#41;;

        var urlPattern = new RegExp&#40;"http&#58;\/\/&#91;\\w\\.\\/&#93;+", "gi"&#41;;//removes the http&#58;//... links
        var urlRemovedXML =lyricsflyRemovedXML.replace&#40;urlPattern,""&#41;;

        var hashPattern = new RegExp&#40;"#&#91;\\w&#93;+", "gi"&#41;;//removes the -#- blahblah
        var hashRemovedXML = urlRemovedXML.replace&#40;hashPattern,""&#41;;
       
        var attPattern = new RegExp&#40;"@&#91;\\w&#93;+", "gi"&#41;;// removes the -@- blahblah
        var attRemovedXML = hashRemovedXML.replace&#40;attPattern,""&#41;;

        var responseXML = new XML&#40;attRemovedXML&#41;;
        return responseXML;
      &#125;

///////REMOVE REGULAR EXPRESSIONS

Απάντηση

Επιστροφή στο “ActionScript και Flex Προγραμματισμός”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 0 επισκέπτες