Skip to main content
markerline
Inspiring
December 6, 2013
Answered

Implicit coercion of a value of type __AS3__.vec:Vector to an unrelated type __AS3__.vec:Vector.<int

  • December 6, 2013
  • 1 reply
  • 3147 views

I have the following code:

I get this error:

Scene 1, Layer 'Layer 1', Frame 1, Line 351067: Implicit coercion of a value of type __AS3__.vec:Vector to an unrelated type __AS3__.vec:Vector.<int>.

import flash.display.Shape;

import flash.events.MouseEvent;

import flash.events.Event;

var g:Shape=new Shape();

var stageCenterX:Number=stage.stageWidth/2;

var stageCenterY:Number=stage.stageHeight/2;

var radius:Number=50;

var circumf:Number=Math.PI*2;

circumf=0;

var degrees:Number=360;

g.graphics.lineStyle(2,0xcc0000);

addChild(g);

g.graphics.moveTo(stageCenterX, stageCenterY+radius);

btn.addEventListener(MouseEvent.CLICK, onBtnClick);

function onBtnClick(e:MouseEvent):void{

    addEventListener(Event.ENTER_FRAME, onEnterFrameEvent);

}

function onEnterFrameEvent(e:Event):void{

    circumf+=.1;

    var vectorcommands:Vector=new Vector.<int>;//(360, true);

    for (var vcmd:int=0;vcmd<360; vcmd++){

        vectorcommands.push(vcmd);

    }

    var vectorargs:Vector=new Vector.<Number>;//(720, true);

    for (var vargs:int=0; vargs<720; vargs++){

        vectorargs.push(Math.sin(vargs/degrees)*radius);

        vectorargs.push(Math.cos(vargs/degrees)*radius);

    }

    for (var i:int=0; i<degrees*circumf; i++){

       

        //g.graphics.lineTo(Math.sin(i/degrees)*radius+stageCenterX,Math.cos(i/degrees)*radius+stageCenterY);

        g.graphics.drawPath(vectorcommands,vectorargs);   //// LINE WITH ERROR

    }

}

The question is, how do I properly push vectors?  I am much more familiar with Arrays but the drawPath method uses Vectors.

This topic has been closed for replies.
Correct answer ___x-_V_P_-x___

Yes, that clamshell is precisely what I get.  I would like a circle to be formed without interior lines.  It seems that I have done such a thing successfully in the past but can't locate my files.  In trying to recreate the steps, this is the unexpected result that I get... what you have shown in the screenshot.


i think its because you have to say moveTo the last position otherwise it is starting from the origional position.

1 reply

Participating Frequently
December 6, 2013

var vectorcommands:Vector.<int> = new Vector.<int>();

var vectorargs:Vector.<number> = new Vector.<number>();

markerline
Inspiring
December 7, 2013

Oh, how silly of me to not instantiate the Vector properly.  I guess I am learning more about this type of Object.

However the desired result to draw a circle on the stage with the drawPath method does not occur.  Can you tell me what I am doing wrong in my code besides what you have fixed, VIP?

Participating Frequently
December 7, 2013

curveTo would produce results similar to lineTo.  But drawCircle SHOULD work.  However in testing drawCircle, it seems to draw the entire circle in one snap, rather than "drawing" it according to EnterFrame, one-pixel-at-a-time as the frames go by on the virtual timeline at runtime.  That is why I wanted to use lineTo.

Have you tried testing the lineTo method using my code above and adding a btn Sprite to the stage manually to initialize the function call when the button is bressed?


I just tried now... here the results i have.....is it the same as yours?