A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: How to control only portion of mc-line?

  1. #1
    Member
    Join Date
    Sep 2014
    Posts
    75

    How to control only portion of mc-line?

    Dear All,

    Code:

    //this code will create a line on stage from(x1=10, y1=10) to (x2=200, y2=200).

    var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
    mc.moveTo(10, 10);
    mc.lineStyle(1.5, 0xFF0000, 100);
    mc.lineTo(200, 200);

    Is there any way to control just portion of this created line. What needed is to give (_alpha=0) ONLY to the portion of the line which is greater than (x=100, y=100)???

    Thanks!

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

    Haven't figured a way to do it dynamically, but you can simply do this, or something similar;
    PHP Code:
    var mc:MovieClip this.createEmptyMovieClip("mc"this.getNextHighestDepth());

    var 
    minX:Number 100;
    var 
    minY:Number 100;

    var 
    maxX:Number 300;
    var 
    maxY:Number 300;

    mc.moveTo(10,10);

    mc.lineStyle(5.5,0xFF0000,10);
    mc.lineTo(minX,minY);

    mc.lineStyle(1.5,0xFFCC00,100);
    mc.lineTo(maxX,maxY); 
    was wondering why have it drawing more if you are not going to see it anyway - setting _alpha to zero
    Last edited by fruitbeard; 04-26-2015 at 02:13 PM.

  3. #3
    Member
    Join Date
    Sep 2014
    Posts
    75
    Quote Originally Posted by fruitbeard View Post
    Hi,
    was wondering why have it drawing more if you are not going to see it anyway - setting _alpha to zero
    it is for a game where its borders isn't the stage borders. lines are drawn in a random way, and the part of any line which is outside the borders of the game should be invisible by setting alpha to zero.

    thank you,
    your code is a good starting point for starting to figure out how to make it dynamic.

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

    Does this help any further, I'm not so sure on the drawing type stuff, don't rwally use it that much.

    PHP Code:
    var mc:MovieClip this.createEmptyMovieClip("mc"this.getNextHighestDepth());

    var 
    minX:Number 100;
    var 
    minY:Number 100;

    var 
    maxX:Number 300;
    var 
    maxY:Number 287;

    function 
    doDraw(a:Numberb:Numberc:Numberd:Number):Void
    {
        
    mc.moveTo(10,10);

        
    mc.lineStyle(5.5,0xFF0000,25);
        
    mc.lineTo(a,b);

        if ((
    a) && (b))
        {
            
    mc.lineStyle(1.5,0xFFCC00,100);
            
    mc.lineTo(c,d);
        }
    }

    doDraw(minX,minY,maxX,maxY); 

  5. #5
    Member
    Join Date
    Sep 2014
    Posts
    75
    Quote Originally Posted by fruitbeard View Post
    Hi,

    Does this help any further, I'm not so sure on the drawing type stuff, don't rwally use it that much.

    PHP Code:
    var mc:MovieClip this.createEmptyMovieClip("mc"this.getNextHighestDepth());

    var 
    minX:Number 100;
    var 
    minY:Number 100;

    var 
    maxX:Number 300;
    var 
    maxY:Number 287;

    function 
    doDraw(a:Numberb:Numberc:Numberd:Number):Void
    {
        
    mc.moveTo(10,10);

        
    mc.lineStyle(5.5,0xFF0000,25);
        
    mc.lineTo(a,b);

        if ((
    a) && (b))
        {
            
    mc.lineStyle(1.5,0xFFCC00,100);
            
    mc.lineTo(c,d);
        }
    }

    doDraw(minX,minY,maxX,maxY); 
    Some adjustment to your code:

    var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
    var minX:Number = 100;
    var minY:Number = 100;
    var maxX:Number = 300;
    var maxY:Number = 300;
    var boundaryX:Number = 200;
    function doDraw(xmin:Number, xmax:Number, ymin:Number, ymax:Number, xboundary:Number):Void {
    mc.moveTo(xmin, ymin);
    //Think about the boundary as a vertical line fron top of stage to the bottom, at e.g. x=200
    if (xmax>xboundary) {
    //Make Interpolation, to get yboundary. (xboundary, yboundary) the point at which the drawn line crosses the boundary(vertical line).
    var yboundary:Number = ymax-((xmax-xboundary)*(ymax-ymin)/(xmax-xmin));
    mc.lineStyle(5.5, 0xFF0000, 25);
    mc.lineTo(xboundary, yboundary);
    mc.lineStyle(1.5, 0xFFCC00, 100);
    mc.lineTo(xmax, ymax);
    } else {
    mc.lineStyle(5.5, 0xFF0000, 25);
    mc.lineTo(xmax, ymax);
    }
    }
    doDraw(minX, maxX, minY, maxY, boundaryX);

    try it with e.g.
    var boundaryX:Number = 200;
    and
    var boundaryX:Number = 350;

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    I knew you would figure it out

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