SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    From Where???
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can't get dynamically loaded text to animate!

    Hi all,

    I am having trouble trying to animate my dynamically loaded text in flash MX. I have used some action script which calls the .txt file and loads it in a text field, this is the only way I know how to do it. The only problem is I can't turn the text field into a symbol as when I do this the flash movie won't load the text anymore. I have tried to assign a path but I think I am not doing it correctly. I also tried to place the action script which loads the text into the symbol itself then place the symbol onto the main timeline but this also has not worked.

    I'm not sure what else to do. All I really want to be able to do is apply some alpha transitions to the text field so that it loops smoothly, also I would like to apply some animation effects to it.

    Is there a way to achieve this? I hope so.

    thanks in advance to anyone who can help with this.

    MD Geist
    "My lyrics are encrypted in Hieroglyphic scriptures so you can picture this.....I make my point like a pyramid"

  2. #2
    SitePoint Zealot flashswami's Avatar
    Join Date
    Jun 2002
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Download this-

    http://www.flashswami.com/downloads/text_dup.zip

    I did it in Flash 5 quite awhile ago so (assuming you use the new LoadVars() function) some of it won't be relevant- the bit you need is the code that uses a for loop to spit out the text into seperate movieclips.

    have alook, see if its any help and if it isn't we'll go through it.
    FlashSwami //Flash & server side fun
    DotDragNet //General web help
    [>Now available for freelance web work<]

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    From Where???
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks flashswami,

    I'll get started on it.

    NIce one

    MD Geist
    "My lyrics are encrypted in Hieroglyphic scriptures so you can picture this.....I make my point like a pyramid"

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    From Where???
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi flashswami,

    I tried and failed misserably, I could'nt figure out which part of the code to put into my movie and where.

    The bit that I think I need is the part which put's the text into a movie clip, this would mean that I could maipulate the movie clip with alpha tweens etc, and thus animate the text. If it is possible for you isolate in your code exactly how it put's the dynamic text into a movieclip, I would really appreciate it, I apologise, I'm just a novice at this programming stuff. Hopefully one day I'll be answering some of these questions.

    Thanks in advance

    MD Geist
    "My lyrics are encrypted in Hieroglyphic scriptures so you can picture this.....I make my point like a pyramid"

  5. #5
    SitePoint Zealot flashswami's Avatar
    Join Date
    Jun 2002
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're absolutley correct- always make anything that you need to manipulate a movieclip- that way you have control over it.

    OK, what this script does is to take a dynamically loaded word and make it animated by splitting the word into an array and then feeding each element of this array into a movieclip of its own. So we start off with a text file like so-

    Code:
    //should say hello here but sitepoints editor is truncating it
    myWord=h:e:l:l:o
    Note the ':' between each letter- this is imperative to allow the array.split() method which will be used later on to feeed the text into an array. For now, save that as mytext.txt. Now transfer your attention to MX and look at this code-

    Code:
    //hides the seed clip
    _root.text_mc._visible=false;
    //loads in and deals with the loaded text
    loadVarsText = new loadVars();
    loadVarsText.load("mytext.txt");
    loadVarsText.onLoad = function(success) {
    	if (success) {
    		//do something
    	} else {
    		//do something else
    	}
    }
    What this code does is to create a new loadvars object, tell it what to load and create a function that decides what to do next depending on wether the text was successfully loaded in or not.

    Now, note the very top line of code. What this does is to hide the 'template' movieclip- this movieclip is what will get duplicated with each duplication storing one letter from the text.

    Okay, now its time to replace the 'do something' bits with real code-

    Code:
    //hides the seed clip
    _root.text_mc._visible=false;
    //loads in and deals with the loaded text
    loadVarsText = new loadVars();
    loadVarsText.load("mytext.txt");
    loadVarsText.onLoad = function(success) {
    	if (success) {
    //creates a new array
    	 textHolder= new Array();
    //splits the variable 'myWord' defined in your text file
             textHolder = _root.myWord.split(":");
    //sets x to have a value of the same number of items in the new array
             x=textHolder.length;
    //a for loop that duplicates the movieclip called 'text_mc'
    //and pushes each letter into the dynamic text box in each
    //duplicated clip
             for (i=0; i<=x; i++) {
              _root.text_mc.duplicateMovieClip ("letter_"+i, i);
              _root["letter_"+i].input = textHolder[i-1];
    //spaces them out evenly, one on top of the other
               if (i != 1) {
    	   _root["letter_"+i]._y = _root["letter_"+(i-1)]._y+_root["letter_"+(i-1)]._height+10;
    			}
        }
    	} else {
    		//do something else
    	}
    }
    Thats it really. Obviously the effect is not the same- you can easily add alpha tweens or whatever effect you need.

    Post back if its still not happening for you
    FlashSwami //Flash & server side fun
    DotDragNet //General web help
    [>Now available for freelance web work<]

  6. #6
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    From Where???
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still does'nt appear to be working, I keep receiving this message in the output box:

    Scene=Scene 1, Layer=Layer 1, Frame=1: Line 2: Statement must appear within on/onClipEvent handler
    _root.text_mc._visible=false;

    Scene=Scene 1, Layer=Layer 1, Frame=1: Line 4: Statement must appear within on/onClipEvent handler
    loadVarsText = new loadVars();

    Scene=Scene 1, Layer=Layer 1, Frame=1: Line 5: Statement must appear within on/onClipEvent handler
    loadVarsText.load("load_text.txt");

    Scene=Scene 1, Layer=Layer 1, Frame=1: Line 6: Statement must appear within on/onClipEvent handler
    loadVarsText.onLoad = function(success) {

    At the moment I have assigned the script to the instance of the movieclip on the main movie timeline, as in my movie I do not have a button to activate the function, I just need it to start automatically. It's saying I need to use the onClipEvent handler, but I'm not sure how I should implement it within the code, syntax wise, I tried to just put the onClipEvent handler at the beginning of your code but flash was having none of it. Could you show me the correct syntax, or maybe I'm putting the code in the wrong place.

    Thanks for your help with this.

    MD Geist
    "My lyrics are encrypted in Hieroglyphic scriptures so you can picture this.....I make my point like a pyramid"

  7. #7
    SitePoint Zealot flashswami's Avatar
    Join Date
    Jun 2002
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Apologies- there was an error in my code- here's teh correct code-

    Code:
    loadVarsText.load("mytext.txt");
    loadVarsText.onLoad = function(success) {
    	if (success) {
    //creates a new array
    	 textHolder= new Array();
    //splits the variable 'myWord' defined in your text file
             textHolder = this.myWord.split(":");
    //sets x to have a value of the same number of items in the new array
             x=textHolder.length;
    //a for loop that duplicates the movieclip called 'text_mc'
    //and pushes each letter into the dynamic text box in each
    //duplicated clip
             for (i=0; i<=x; i++) {
              _root.text_mc.duplicateMovieClip ("letter_"+i, i);
              _root["letter_"+i].input = textHolder[i-1];
    //spaces them out evenly, one on top of the other
               if (i != 1) {
    	   _root["letter_"+i]._y = _root["letter_"+(i-1)]._y+_root["letter_"+(i-1)]._height+10;
    			}
        }
    	} else {
    		trace("nope");
    	}
    }
    stop();
    And here's a source file-

    http://www.flashswami.com/downloads/...c_text_gen.zip
    FlashSwami //Flash & server side fun
    DotDragNet //General web help
    [>Now available for freelance web work<]

  8. #8
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    From Where???
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry for not replying sooner,

    Thanks for the help flashswami, I've got this
    sorted now.

    Thanks again for all the help

    MD Geist
    "My lyrics are encrypted in Hieroglyphic scriptures so you can picture this.....I make my point like a pyramid"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •