A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: Is this too processor demanding?

  1. #1
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389

    Is this too processor demanding?

    Hi,

    Does this make any sense? I'm trying to delete "ind" before each next function call but I can't. Could it be because this is happening too quick?

    Code:
    var aFonts:Array = ["Times", "Calibri", "Aparajita", "Times", "Trebuchet MS", "Verdana", "Andalus", "Arial"];
    var aFontSize:Array = ["18", "22", "26", "28", "30", "34", "38", "42"];
    var aFontColor:Array = ["0xFF0000", "0x003300", "0xFFFFFF", "0x000033", "0x99CC00", "0x6666CC", "0xFF66CC", "0xCC66CC"];
    var aBoldness:Array = ["true", "false", "true", "true", "false", "false", "true", "false"];
    var aItalic:Array = ["true", "false", "true", "false", "true", "false", "true", "false"];
    
    var theX = Math.floor(Math.random() * Stage.width);
    var theY = Math.floor(Math.random() * Stage.height);
    
    function textFormatter(a, b)
    {
        var select:Number = Math.floor(Math.random() * aFonts.length - 1);
        var tFormatter:TextFormat = new TextFormat();
        tFormatter.font = aFonts[select];
        tFormatter.size = aFontSize[select];
        tFormatter.color = aFontColor[select];
        tFormatter.bold = aBoldness[select];
        tFormatter.italic = aItalic[select];
        ind.setTextFormat(a, b, tFormatter);
    }
    
    var ind:TextField = this.createTextField("ind", this.getNextHighestDepth(), theX, theY, 800, 500);
    ind.text = "In... inde... independència!";
    ind.antiAliasType = "advanced";
    ind.embedFonts = true;
    ind.selectable = false;
    ind._rotation = Math.floor(Math.random() * 90) - 45;
    ind._alpha = Math.round(Math.random() * 100) + 10;
    
    var aAudio:Sound = new Sound();
    aAudio.attachSound("critsInde");
    aAudio.setVolume(10);
    aAudio.start();
    
    var audioPosition:Number;
    var audioDuration:Number;
    
    this.onEnterFrame = function() {	
    	audioDuration = aAudio.duration/1000;
    	audioPosition = aAudio.position/1000;
    	
    	trace(aAudio.position);
    	
    	if(audioPosition == 1.022){
    		trace("Primera sÃ*l·laba");
    		textFormatter(0,6);
    	}
    	
    	if(audioPosition == 1.022){
    		trace("Segon crit");
                    ind.removeTextField();
    		textFormatter(6,14);
    	}
    	
    	if(audioPosition == 2.136){
    		trace("Crit final");
                    ind.removeTextField();
    		textFormatter(14,ind.text.length);
    	}
    };
    
    aAudio.onSoundComplete = function() {
    	aAudio.stop("critsInde");
    	delete onEnterFrame;
    };

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    I had to test this with a larger sound file as I don't have your independencia file, or your *.fla,

    I don't think it's too processor intensive, after all the sound is only about 3 - 4 seconds long if I remember correctly, but you could possibly use a timer or setinterval to slow the function call time, get it working how you want first, then change anything else.

    I commented out some things here just to see it working ( alpha, rotation and different x,y values) all replaceable .

    Is this what you desire???
    PHP Code:
    var aFonts:Array = ["Times""Calibri""Aparajita""Times""Trebuchet MS""Verdana""Andalus""Arial"];
    var 
    aFontSize:Array = ["18""22""26""28""30""34""38""42"];
    var 
    aFontColor:Array = ["0xFF0000""0x003300""0xFFFFFF""0x000033""0x99CC00""0x6666CC""0xFF66CC""0xCC66CC"];
    var 
    aBoldness:Array = ["true""false""true""true""false""false""true""false"];
    var 
    aItalic:Array = ["true""false""true""false""true""false""true""false"];

    //var theX = Math.floor(Math.random() * Stage.width);
    //var theY = Math.floor(Math.random() * Stage.height);
    var theX 20;
    var 
    theY 20;

    function 
    textFormatter(ab)
    {
        var 
    select:Number Math.floor(Math.random() * aFonts.length 1);
        var 
    tFormatter:TextFormat = new TextFormat();
        
    tFormatter.font aFonts[select];
        
    tFormatter.size aFontSize[select];
        
    tFormatter.color aFontColor[select];
        
    tFormatter.bold aBoldness[select];
        
    tFormatter.italic aItalic[select];
        
    ind.setTextFormat(a,b,tFormatter);
    }

    var 
    ind:TextField this.createTextField("ind"this.getNextHighestDepth(), theXtheY800500);
    ind.text "In... ";
    ind.antiAliasType "advanced";
    //ind.embedFonts = true;
    ind.selectable false;
    //ind._rotation = Math.floor(Math.random() * 90) - 45;
    //ind._alpha = Math.round(Math.random() * 100) + 10;

    var aAudio:Sound = new Sound();
    aAudio.attachSound("critsInde");
    aAudio.setVolume(10);
    aAudio.start();

    var 
    audioPosition:Number;
    var 
    audioDuration:Number;

    this.onEnterFrame = function()
    {
        
    audioDuration aAudio.duration 1000;
        
    audioPosition aAudio.position 1000;

        
    trace(aAudio.position);

        if (
    audioPosition >= 1.022)
        {
            
    trace("Primera sÃ*l·laba");
            
    ind.text "In... ";
            
    textFormatter(0,ind.text.length);
        }

        if (
    audioPosition >= 1.022)
        {
            
    trace("Segon crit");
            
    ind.text "inde... ";
            
    textFormatter(0,ind.text.length);
        }

        if (
    audioPosition >= 2.136)
        {
            
    trace("Crit final");
            
    ind.text "independència!";
            
    textFormatter(0,ind.text.length);
        }
    };

    aAudio.onSoundComplete = function()
    {
        
    aAudio.stop("critsInde");
        
    delete this.onEnterFrame;
        
    ind.removeTextField();
    }; 

  3. #3
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    Good morning, Fruit,

    thanks, at least it's closer to what I want to do. I had been testing different ways and it worked randomly, skipping syllables and responding weirdly. This is the result of the code. I wonder why the "e" in inde is always a larger format. I think I am calling it with the correct parameters.

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    You dont really need to pass the text lengths over if the text is changing each time, so here with a few alterations.
    You did not embed some the fonts correctly so I am surprised you even go it to publish.

    Tahoma and Andalus do not have bold or Italic options so no good for embedding for this project.

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    If you use the *.fla I sent with this code instead.
    PHP Code:
    var aFonts:Array = ["Times""Calibri""Aparajita""Times""Trebuchet MS""Verdana""Trebuchet MS""Arial"];
    var 
    aFontSize:Array = ["18""22""26""28""30""34""38""42"];
    var 
    aFontColor:Array = ["0xFF0000""0x003300""0xFFFFFF""0x000033""0x99CC00""0x6666CC""0xFF66CC""0xCC66CC"];
    var 
    aBoldness:Array = ["true""false""true""true""false""false""true""false"];
    var 
    aItalic:Array = ["true""false""true""false""true""false""true""false"];

    //var theX = Math.floor(Math.random() * Stage.width);
    //var theY = Math.floor(Math.random() * Stage.height);
    var theX 20;
    var 
    theY 20;

    var 
    pointA:Number 1.022;
    var 
    pointB:Number 2.136;
    var 
    select:Number;
    var 
    tFormatter:TextFormat;

    function 
    textFormatter()
    {
        
    select Math.floor(Math.random() * aFonts.length);
        
    tFormatter = new TextFormat();
        
    tFormatter.font aFonts[select];
        
    tFormatter.size aFontSize[select];
        
    tFormatter.color aFontColor[select];
        
    tFormatter.bold aBoldness[select];
        
    tFormatter.italic aItalic[select];
        
    ind.setTextFormat(tFormatter);
        
    //trace(select);
    }

    var 
    ind:TextField this.createTextField("ind"this.getNextHighestDepth(), theXtheY800500);
    ind.text "In... ";
    ind.antiAliasType "advanced";
    ind.embedFonts true;
    ind.selectable false;
    //ind._rotation = Math.floor(Math.random() * 90) - 45;
    //ind._alpha = Math.round(Math.random() * 100) + 10;
    ind.setTextFormat("Arial",16,"0x000000");

    var 
    aAudio:Sound = new Sound();
    aAudio.attachSound("critsInde");
    aAudio.setVolume(10);
    aAudio.start(0,1);

    var 
    audioPosition:Number;
    var 
    audioDuration:Number;

    onEnterFrame = function ()
    {
        
    audioDuration aAudio.duration 1000;
        
    audioPosition aAudio.position 1000;
        
    //trace(audioDuration);
        //trace(aAudio.position);
        
        
    if (audioPosition pointA)
        {
            
    //trace("Primera sÃ*l·laba");
            
    ind.text "In... ";
        }
        if (
    audioPosition >= pointA && audioPosition pointB)
        {
            
    //trace("Segon crit");
            
    ind.text "inde... ";
        }
        if (
    audioPosition >= pointB)
        {
            
    //trace("Crit final");
            
    ind.text "independència!";
        }
        
    textFormatter();
        
    //trace("Sound playing @ " + audioPosition); 
    };

    aAudio.onSoundComplete = function()
    {
        
    delete onEnterFrame;
        
    trace("Sound stopped...");
        
    ind.removeTextField();
    }; 

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Actually I fixed the font issues, you should be able to see what I've done

  7. #7
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    Hi, Fruit,

    thanks again. At least, now I see what you meant by embedding the fonts properly. (That, I'll change)

    I'll use this last example to work on it applying it to an attached movie clip so I can call it with setInterval. This is how I really mean to do it and that's why I was asking how to use the getTextFormat as I started the post. I need each frame maintaining the same format. Do you simply create the next piece of text and format it equal to the getTextFormat method? Like: inde.setTextFormat = my_fmt from the previous piece of text??

    my_fmt:TextFormat = ind.getTextFormat();

  8. #8
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    I'm getting slightly lost here, so you do not want the text to change format at all, if you do want it to change why do you need the previous format.

    Do you want the text to be in the same position and only rotate or in different positions each part.

    You still need to embed the fonts properly, if you look in the library you will see that they have no font family associated with them, I keep saying that Tahoma and Andalus have no italic or bold italic settings so therefore will not show up if randomly chosen
    Last edited by fruitbeard; 04-07-2014 at 10:32 AM.

  9. #9
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    i undrstand about the fonts now. Got the message on the underground... It's keeping the same format as the starrting text what i need

  10. #10
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    so do you need the format to change at all, perhaps make a picture of how you want the text to go and go back to

  11. #11
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    well, I do want the coming frames keeping the same random format as the first one. Was that the way to use getTextFormat? I'm on a bus right now

  12. #12
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    please make an image when you get home of how you want the text to start and how you want the following text to start and finish, it will help me enormously to figure out what you actually want

    adobe:

    my_txt.getTextFormat()
    my_txt.getTextFormat(index)
    my_txt.getTextFormat(beginIndex, endIndex)
    Last edited by fruitbeard; 04-07-2014 at 11:45 AM.

  13. #13
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    yes, I will. Thanks. Sorry for my confusing posts

  14. #14
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389

  15. #15
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    so you want the text to change, but keep whatever format it is all the way along

    same format from start to finish, whatever random font,colour,size it has at beginning, keep it the same until the end

  16. #16
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi

    I think this??

  17. #17
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    Hi, Fruit, thanks,

    it's no more no less than what I wanted. Only thing I am transposing or passing the code to Flash 8 and some fonts do not seem to show like you were saying. Thanks so much though. I do have some work to do from here.

  18. #18
    Junior Member
    Join Date
    Apr 2014
    Posts
    8
    Oh nice!

  19. #19
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,145
    When I was doing AS2 stuff, I didn't use attachMovieClip. I duplicated movieclips so I could design the "original" clip on stage then duplicate it. Here's some code showing duplicating clips, populating the data, placing it, etc.

    Code:
    for(var i=0;i<aFeaturedVideos.length;i++){
            mcItemHolder.mcItem.duplicateMovieClip("mcItem_" + i,100+i);
            var mcNewItem = mcItemHolder.mcItem["mcItem_" + i];
            mcNewItem._y = i * 90;
            mcNewItem._x = 0;
            mcNewItem.mcPlaying._visible = false;
            mcNewItem.mcTitle.text = "Featured Videos Number " + i;
            mcNewItem.sItemType = "featuredVideos";
            var nTextHeight = mcNewItem.mcTitle.textHeight;
            mcNewItem.mcTitle._y = Math.floor((80 - nTextHeight)/2);
    }
    Put all your clips inside clips - put a mcThumbsHolder empty clip on the stage and load the mcThumb clips into it.

  20. #20
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    Thanks Moot, but the content like the runtime created text will not be duplicated, will it?

    I have a little issue now. I've changed my mind and I want to duplicate my first text and I've asked Fruit so much I hate to post using his work but I need to finish this job urgently.

    I'm attaching one clip from the main timeline and as soon as the sound called from that clip I need to attach it more times, but without me removing it from the stage, if I call the function in the main timeline, the text I finally managed to place in my holding clip disappears. Besides the randomness I'm trying to achieve only works once and the rest of the texts all appear in the same place even if I get different random traces. (Perhaps the traces are not related because I'm very confused with levels)

    Do you think you could lend me a hand?

    I'm attaching it to clarify my question.


    Attachment 74867

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center