SitePoint Sponsor

User Tag List

Results 1 to 24 of 24

Hybrid View

  1. #1
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Outputting a 1 pixel dot to the page i nFlash?

    I'm working on a little project for myself. I want to have a movie that outputs random dots to a Flash movie. Getting a random set of x,y coordinates from the movie (400x230). I htink I can just use random (from 0-screen.width?). I'm gonna test it myself but what would be the procedure? I guess I can use a movie clip instead of the dot.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  2. #2
    ...
    Join Date
    Jan 2002
    Location
    London, UK
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So your looking for Flash to display a load of randomly placed dots within a movie?

    if so here's one way, place a movieclip with an instance name of 'circle' somewhere outside your 400*230 stage and use the following Actionscript to display it randomly within the stage 50 times.

    Code:
    var numCircles = 50;
    var i = 1;
    do {
    	duplicateMovieClip(circle, "cir" +i, i);
    	_root["cir" +i]._x = Math.floor(Math.random()*400);
    	_root["cir" +i]._y = Math.floor(Math.random()*230);
    } while (i++ < numCircles);

  3. #3
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great...I had something similar. Nice to know I was on the right track. My question is now is how do I get it come in at random, non-stop?

    I want to have say 100 or so fading in at random, I'll put the fading out part in the movieclip. Basically I want it to "twinkle" sort of like stars.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  4. #4
    ...
    Join Date
    Jan 2002
    Location
    London, UK
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see what you mean now

    for your star animation you could have a movieclip fading in and out 'starMovieClip' and on the last blank frame place:

    this.removeMovieClip();

    starMovieClip is nested in 'holderMovieClip' which has:

    Code:
    // frame 1
    var i = 1;
    function displayStars() {
    	if (i != 100){
    	duplicateMovieClip(_root.holderMovieClip.starMovieClip, "star" + i, i);
    	_root.holderMovieClip["star" + i]._x = Math.floor(Math.random() * 400);
    	_root.holderMovieClip["star" + i]._y = Math.floor(Math.random() * 230);
    	i++;
    	} else {
    		// do something here once 100 stars have been shown
    	}
    }
    
    // frame 2
    displayStars();
    
    // frame 3 etc.
    displayStars();
    
    and on frame 10 
    gotoAndPlay(2); // so var i isn't set to 1 again.

  5. #5
    ...
    Join Date
    Jan 2002
    Location
    London, UK
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one other quick point (probably stating the obvious ;-)

    for an effect like a twinkling star your better off recreating one using the built in tools in Flash (or which ever vector tool you use - Freehand, Illustrator) than importing a gif - smaller movie at the end.

  6. #6
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yah...I am. I just made a circle using Flash. This kicks ***! The file size is 472 BYTES!!! Here's a link to the movie:
    http://www.the615.com/playground.cfm?image=25

    You rock Chas...I've got another idea for a movie that would be REALLY rad. Would you be interested in helping me on that one as well?
    Last edited by creole; May 15, 2003 at 07:11.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  7. #7
    ...
    Join Date
    Jan 2002
    Location
    London, UK
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats the one!

    yer, whats the idea?

  8. #8
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's the same principle. But instead of having lots of little dots, I would like to have one dot appear (in a random spot), then a second dot appear and have a line connect the two dots. Then simultaneously, a third dot would appear and the first dot would disappear. The line would of course then be drawn to the 3rd dot from the second dot and so on. Note, the line does not actually have to "draw". It can just appear.

    So it would basically be a neverending game of conect the dots.

    I'm using MX. Is there some sort of "line" object? How would you draw a line dynamically?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a quick note to add to Chas' code. Instead of spreading it out over multiple frames, just use MX's new setInterval method.


    Code:
    var i = 1;
    function displayStars() {
    	if (i != 100){
    		_root.holderMovieClip.starMovieClip.duplicateMovieClip("star" + i, i);
    		_root.holderMovieClip["star" + i]._x = Math.floor(Math.random() * 400);
    		_root.holderMovieClip["star" + i]._y = Math.floor(Math.random() * 230);
    		_root.holderMovieClip["star" + i].onEnterFrame = fadeStar;
    		i++;
    	} else {
    		// do something here once 100 stars have been shown
    	}
    }
    fadeStar = function() {
    	if(this._alpha > 10) {
    		this._alpha -= 10;	
    	}
    	else {
    		this.onEnterFrame = null;	
    		this.removeMovieClip();	
    	}
    }
    var myInterval = setInterval(displayStars, 100);
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  10. #10
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Andy,

    Not sure if this was what you were looking for where the lines connect. Super hacked together though.

    Code:
    var i=2;
    var p=100;
    
    function createStar() {
    	_root.star1.duplicateMovieClip("star"+i, i);
    	var thisClip = _root["star"+i];
    	trace (thisClip);
    	thisClip._x = random(Stage.width);
    	thisClip._y = random(Stage.height);
    	var lastI = (i - 1);
    	var lastII = (i - 2);
    	var lastP = (p - 1);
    	if(i > 2) {
    		drawLine(_root["star"+lastI]._x,_root["star"+lastI]._y,
    _root["star"+i]._x,_root["star"+i]._y);
    		_root["star"+lastII].removeMovieClip();
    		_root["lineClip"+lastP].removeMovieClip();
    	}
    	i++;
    }
    function drawLine(startX, startY, endX, endY) {
    	var thisClip = this.createEmptyMovieClip("lineClip"+p, p);
    	thisClip.lineStyle( 2, 0x00000, 100 );
    	thisClip.moveTo( startX, startY );
    	thisClip.lineTo( endX,endY ); 
    	p++;
    }
    var myInterval = setInterval(createStar, 1000);

    And this one fades the lines and stars out.

    Code:
    var i=2;
    var p=100;
    
    function createStar() {
    	_root.star1.duplicateMovieClip("star"+i, i);
    	var thisClip = _root["star"+i];
    	trace (thisClip);
    	thisClip._x = random(Stage.width);
    	thisClip._y = random(Stage.height);
    	var lastI = (i - 1);
    	var lastII = (i - 2);
    	var lastP = (p - 1);
    	if(i > 2) {
    		drawLine(_root["star"+lastI]._x,_root["star"+lastI]._y,
    _root["star"+i]._x,_root["star"+i]._y);
    		_root["star"+lastII].onEnterFrame = fadeMe;
    		_root["lineClip"+lastP].onEnterFrame = fadeMe;
    	}
    	i++;
    }
    function drawLine(startX, startY, endX, endY) {
    	var thisClip = this.createEmptyMovieClip("lineClip"+p, p);
    	thisClip.lineStyle( 2, 0x00000, 100 );
    	thisClip.moveTo( startX, startY );
    	thisClip.lineTo( endX,endY ); 
    	p++;
    }
    
    fadeMe = function() {
    	if(this._alpha > 10) {
    		this._alpha -= 10;
    	}
    	else {
    		this.onEnterFrame = null;
    		this.removeMovieClip();
    	}
    	
    }
    var myInterval = setInterval(createStar, 1000);
    Last edited by freddydoesphp; Nov 13, 2002 at 13:05.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  11. #11
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting...

    I see lots of properties in your code that I didn't know existed.

    stage.width, stage.height, lineStyle,

    Great...I'm planning on learning a lot from the code that you two guys gave me in this ONE exercise!

    One Q though Louie...what are the requirements of the code you just posted?

    What movie clips should exist on the main stage? What frame does this code go on? Etc.

    I'm gonna try it out myself and see if I can figure through it but I'd appreciate you giving me a little hint. It's always a pleasure.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  12. #12
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it working actually...that's really cool.

    @
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  13. #13
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Andy,

    Glad to hear you got it working. When do we get to see it?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  14. #14
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Soon...I got the "functionality" working but now I need to decide what the design will be. It's gonna have to be something angular.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  15. #15
    ...
    Join Date
    Jan 2002
    Location
    London, UK
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's great Louie!

    Going to check out Colin Moock's updated Definitive guide to learn more Flash 6 ActionScript.

    any other recommendations?

    Andy, let us know when you get this sorted

  16. #16
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just wanted to check on this star thing. I'm wanting to use this in a piece I'm doing for work. However, I've only got Flash 5 here at the office. Is it possible to replicate this functionality in v5? If so, then how?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  17. #17
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  18. #18
    ...
    Join Date
    Jan 2002
    Location
    London, UK
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The original version i posted's Flash 5 all be it without some of the bells & whistles

  19. #19
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Andy, you want the line to draw between the two dots and then have the line and a dot fade out until the next dot and line appear? Its just going to be a bit tougher, because we would need to use a preexisting line and bend and twist it to strecth between the two dots.

    I'll try and whip something together a little later on today.

  20. #20
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually Louie, Chas...

    I'm talking about the Stars movie. I'm using the same code that I used previously but it doesn't seem to be working.

    I'm building this ecard for my company and I would love to have those stars twinkling in the background.

    I tried the code that Chas posted but for some reason I can't get it working. It's been so long since I worked on this that I can't quite remember how I got it working the last time. I've even got the original movie clip and for some reason THAT'S not working. Here's the code from that one for reference.

    PHP Code:
    var numCircles 100;
    var 
    10;
    do {
     
    duplicateMovieClip (circle"cir"+ii);
     
    _root["cir"+i]._x Math.floor(Math.random()*400);
     
    _root["cir"+i]._y Math.floor(Math.random()*230);
    } while (
    i++<numCircles); 
    This code gives me the random stars that I need but they all fade out at the same time and they don't come back.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  21. #21
    ...
    Join Date
    Jan 2002
    Location
    London, UK
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Want me to post the FLA when i get home later tonight Creole?

  22. #22
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow..

    That would ROCK Chas! Thanks. I don't know why it's not working for me. I would have thought that the file on my home computer would have been the final version but I guess not.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  23. #23
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Andy,

    You do still have the onClipEvents attached to the circle movie clip, right? The code that fades the circle out.

    BTW
    PHP Code:
    var numCircles 100;
    var 
    10;
    do {
     
    duplicateMovieClip ("circle""cir"+ii);
     
    _root["cir"+i]._x Math.floor(Math.random()*400);
     
    _root["cir"+i]._y Math.floor(Math.random()*230);
    } while (
    i++<numCircles); 

    circle should be in parans like above in the duplicateMovieClip line. Yours a couple of posts above didn't have quotes around it.

  24. #24
    ...
    Join Date
    Jan 2002
    Location
    London, UK
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the attachment.
    Attached Files Attached Files


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
  •