Errors with Gradients in ActionScript - actionscript-3

I am currently receiving the following errors:
Scene 1, Layer 'Layer 1', Frame 1, Line 172 1119: Access of possibly undefined property joints through a reference with static type flash.display:GraphicsGradientFill.
Scene 1, Layer 'Layer 1', Frame 1, Line 173 1067: Implicit coercion of a value of type flash.display:GraphicsSolidFill to an unrelated type Array.
When trying to create gradients like this:
import flash.display.JointStyle;
var stroke:GraphicsGradientFill = new GraphicsGradientFill();
stroke.joints = JointStyle.MITER;
stroke.alphas = new GraphicsSolidFill(0x102020, 1);
var fill:GraphicsGradientFill = new GraphicsGradientFill();
fill.colors = [0x0000FF, 0xEEFFEE];
fill.matrix = new Matrix();
fill.matrix.createGradientBox(70, 70, Math.PI / 2);
var path:GraphicsPath = new GraphicsPath(new Vector.<int>(), new Vector.<Number>);
path.commands.push(1, 2, 2);
path.data.push(125, 0, 50, 100, 175, 0);
var drawing:Vector.<IGraphicsData> = new Vector.<IGraphicsData>();
drawing.push(stroke, fill, path);
graphics.drawGraphicsData(drawing);
What is causing these errors?

Try:
import flash.display.JointStyle;
JointStyle.MITER
Edit: Change stroke.joints = JoinStyle.MITER; => stroke.joints = JointStyle.MITER;
Edit for new errors:
GraphicsGradientFill does not have a property joints and the alphas property expects an array. I think maybe you are looking for GraphicsStroke instead of GraphicsGradientFill for the variable stroke?

Related

Flash Actionscript3 - error 1120

I wanted to ask for some help on an error I have in Flash Professional while using AS3.I keep getting a couple of errors and I am not sure how to correct them. Here are the errors below (5 in total):
Scene 1, Layer 'Content', Frame 4, Line 25, Column 3 1120: Access of undefined property grid.
Scene 1, Layer 'Content', Frame 4, Line 8, Column 1 1120: Access of undefined property grid.
Scene 1, Layer 'Content', Frame 4, Line 9, Column 1 1120: Access of undefined property grid.
Scene 1, Layer 'Content', Frame 4, Line 10, Column 1 1120: Access of undefined property grid.
Scene 1, Layer 'Content', Frame 4, Line 11, Column 1 1120: Access of undefined property grid.
Here is my code for this page, I basically wanna place parts of the XML document into a datagrid:
stop();
//Flash generated imports
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
//Datagrid added from components menu
grid.addColumn("Title");
grid.addColumn("Genre");
grid.addColumn("Runtime");
grid.addColumn("AgeRating");
var loader:URLLoader = new URLLoader(new URLRequest("movieList.xml"));
loader.addEventListener(Event.COMPLETE, onLoaded);
//Added a loop to handle the multiple movie instances
function onLoaded(e:Event):void
{
var xml:XML = new XML(loader.data);
var itemList:XMLList = xml..movie_info;
var len:int = itemList.length();
for(var i:int=0; i<len; i++)
{
grid.addItem({Title:itemList[i].Title,
Genre:itemList[i].Genre,
Runtime:itemList[i].Runtime,
AgeRating:itemList[i].AgeRating});
}
}
Any help would be greatly appreciated :)

Render to texture not functioning

I'm trying to test Stage3D's setRenderToTexture function, but my test code is not providing any output. I was hoping someone could tell me why - I've tried practically everything to get this working. The code I've created is below:
import flash.events.Event;
import flash.display.*;
import flash.display3D.*;
import flash.display3D.textures.Texture;
import AGALMiniAssembler;
//using stage size in several locations for simplicity - needs to be square, 2^n
[SWF(width='512', height='512', backgroundColor='0x000000', frameRate='60')]
//vars
var context0:Context3D;
var vBuff:VertexBuffer3D;
var iBuff:IndexBuffer3D;
var tex0:Texture;
var tex1:Texture;
var vShader:AGALMiniAssembler = new AGALMiniAssembler();
var fShader:AGALMiniAssembler = new AGALMiniAssembler();
var program:Program3D;
//create a square
var square:Shape = new Shape();
square.graphics.beginFill(0xaa00ff,1);
square.graphics.drawRect(10, 10, stage.stageWidth - 20, stage.stageHeight - 20);
//draw square to bitmapdata and create one blank bitmapdata
var tex0data:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,false,0);
tex0data.draw(square);
var tex1data:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,false,0);
//initialize stage3d
stage.stage3Ds[0].addEventListener(Event.CONTEXT3D_CREATE, initStage3D);
stage.stage3Ds[0].requestContext3D();
function initStage3D(e:Event):void {
context0 = stage.stage3Ds[0].context3D;
context0.configureBackBuffer(stage.stageWidth, stage.stageHeight, 0);
//create buffers - simple quad
var vBuff_vec:Vector.<Number> = new <Number>[-1, -1, 0, 0, 1,
-1, 1, 0, 0, 0,
1, 1, 0, 1, 0,
1, -1, 0, 1, 1];
var iBuff_vec:Vector.<uint> = new <uint>[0, 1, 2, 0, 2, 3]
vBuff = context0.createVertexBuffer(4, 5);
vBuff.uploadFromVector(vBuff_vec, 0, 4);
iBuff = context0.createIndexBuffer(6);
iBuff.uploadFromVector(iBuff_vec, 0, 6);
//load bitmapdata into textures - square to tex0 and blank to tex1
tex0 = context0.createTexture(tex0data.width,tex0data.height,'bgra',false);
tex0.uploadFromBitmapData(tex0data);
tex1 = context0.createTexture(tex1data.width, tex1data.height,'bgra',true);
tex1.uploadFromBitmapData(tex1data);
//create and upload simple shader program
vShader.assemble('vertex', 'mov v0, va1 \n'+ //uv coords to v0
'mov op, va0'); //output xyz coords
fShader.assemble('fragment', 'tex oc, v0, fs0 <2d, linear, nomip>'); //output texture at fs0
program = context0.createProgram();
program.upload(vShader.agalcode, fShader.agalcode);
context0.setProgram(program);
//set buffers
context0.setVertexBufferAt(0, vBuff, 0, 'float3');
context0.setVertexBufferAt(1, vBuff, 3, 'float2');
//prep rendering
addEventListener(Event.ENTER_FRAME, render);
}
function render(e:Event):void {
context0.clear();
//render tex0 onto tex1
context0.setRenderToTexture(tex1);
context0.setTextureAt(0, tex0);
context0.drawTriangles(iBuff);
//render tex1 to back buffer and present
context0.setTextureAt(0, tex1);
context0.setRenderToBackBuffer();
context0.drawTriangles(iBuff);
context0.present();
}
EDIT: I have noticed that changing the color of the blank bitmap does change the color of the final output - it's being displayed, but the square isn't being rendered to it.
FINALLY figured this out! There is a subtle, but important, step that must be taken before a texture is viable as a render target - it must be cleared after the render target is switched. Revising the render function as follows causes the program to function as expected:
function render(e:Event):void {
//render tex0 onto tex1
context0.setRenderToTexture(tex1);
context0.clear();
context0.setTextureAt(0, tex0);
context0.drawTriangles(iBuff);
//render tex1 to back buffer and present
context0.setTextureAt(0, tex1);
context0.setRenderToBackBuffer();
context0.clear();
context0.drawTriangles(iBuff);
context0.present();
}

How to attach a moiveClip into as3isolib grid?

I am a beginner with using AS3 and as3isolib. I am trying to add some MC from the fla library into an isoGrid object. I tried to use addChild() method of the IsoGrid class but it gave me an error saying: 1067: Implicit coercion of a value of type [MovieClip Name] to an unrelated type as3isolib.data:INode. Which I think wants me to use the node class.
Any idea how to do such a thing?
Thank you in advance.
as3isolib use it's own display list like rendering tree, add all nodes in this tree must implements as3isolib.data:INode. There are two possibility to add flash native display objects to the IsoScene:
Take a look on this small tutorial:
//create IsoView, IsoScene and IsoGrid - default from as3isolib
var view:IsoView = new IsoView();
view.setSize(stage.stageWidth, stage.stageHeight);
addChild(view);
var scene:IsoScene = new IsoScene();
view.addScene(scene);
var grid:IsoGrid = new IsoGrid({cellSize:32});
grid.setGridSize(800, 600);
grid.stroke = new Stroke(0, 0x576F33);
grid.render();
//create iso box, just for demo
var obj:IsoBox = new IsoBox();
obj.setSize(32, 32, 64);
obj.moveTo(5*32, 5*32, 1);
//first possiblity to add flash.display.Shape to the iso scene - using IsoSprite.sprites
var isoSprite:IsoSprite = new IsoSprite();
isoSprite.moveTo(5*32, 7*32, 1);
var shape1:Shape = new Shape();
shape1.graphics.beginFill(0xFF0000, 1);
shape1.graphics.drawRect(0, 0, 32, 32);
isoSprite.sprites = [shape1];
//second possiblity to add flash.display.Shape to the iso scene - using IsoDisplayObject.container
var isoObj:IsoDisplayObject = new IsoDisplayObject();
isoObj.moveTo(7*32, 7*32, 1);
var shape2:Shape = new Shape();
shape2.graphics.beginFill(0x0000FF, 1);
shape2.graphics.drawRect(0, 0, 32, 32);
isoObj.container.addChild(shape2);
//add all objects to the scene and render all
scene.addChild(grid);
scene.addChild(obj);
scene.addChild(isoSprite);
scene.addChild(isoObj);
scene.render();

Having an object move to more than one place using tween class in AS3?

Hi I am trying to make an object, in this case 'ship_mc', move to 3 different points on a screen, but i want to use the tween class. I'm not sure why its not working, any help would be greatly appreciated.
my code looks like this
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
var myTween01:Tween = new Tween(this, "x", Regular.easeIn, 1416, 973, 4, true);
var myTween02:Tween = new Tween(this, "y", Regular.easeIn, 206, 446, 4, true);
var myTween03;
var myTween04;
var myTween05;
var myTween06;
myTween01.addEventListener(TweenEvent.MOTION_FINISH, onFinish);
function onFinish(e:TweenEvent):void {
myTween03:Tween = new Tween(this, "x", None.easeIn, 973, 695, 4, true);
myTween04:Tween = new Tween(this, "y", None.easeIn, 446, 222, 4, true);
}
myTween04.addEventListener(TweenEvent.MOTION_FINISH, onFinish1);
function onFinish1(e:TweenEvent):void {
myTween05:Tween = new Tween(this, "x", None.easeIn, 695, 374, 4, true);
myTween06:Tween = new Tween(this, "y", None.easeIn, 222, 239, 4, true);
}
and this is the error I am getting
Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 15 1067: Implicit coercion of a value of type fl.transitions:Tween to an unrelated type Class.
Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 15 1188: Illegal assignment to class Tween.
Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 16 1067: Implicit coercion of a value of type fl.transitions:Tween to an unrelated type Class.
Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 16 1188: Illegal assignment to class Tween.
Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 22 1067: Implicit coercion of a value of type fl.transitions:Tween to an unrelated type Class.
Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 22 1188: Illegal assignment to class Tween.
Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 23 1067: Implicit coercion of a value of type fl.transitions:Tween to an unrelated type Class.
Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 23 1188: Illegal assignment to class Tween.
thanks, i know people will suggest using tweenlite, but i would like to know what the problem is here, otherwise I wont learn!
The error messages you are receiving tell you the lines where the problems are occuring: 15, 16, 22 and 23:
15: myTween03:Tween = new Tween(this, "x", None.easeIn, 973, 695, 4, true);
16: myTween04:Tween = new Tween(this, "y", None.easeIn, 446, 222, 4, true);
22: myTween05:Tween = new Tween(this, "x", None.easeIn, 695, 374, 4, true);
23: myTween06:Tween = new Tween(this, "y", None.easeIn, 222, 239, 4, true);
Your code for the first two tweens works fine, so what is the only difference between the first two, and the rest of the tweens? The way you declared them. You need to declare myTween03, myTween04, myTween05 and myTween06 as tweens to prevent the errors from being thrown, as it thinks you are trying to initialise a default class as a tween otherwise. Change:
var myTween03;
var myTween04;
var myTween05;
var myTween06;
to
var myTween03:Tween;
var myTween04:Tween;
var myTween05:Tween;
var myTween06:Tween;
and initialize them the same way you did for the first and second tween:
myTween03 = new Tween(this, "x", None.easeIn, 973, 695, 4, true);
myTween04 = new Tween(this, "y", None.easeIn, 446, 222, 4, true);
This basically states the variables will be initialized as tweens later on in the code, and will prevent those errors from being thrown.

converting Actionscript 2 code into Actionscript 3

Recently I followed and made the 3d carousel in AS2, but I'm looking to use it and make it in AS3. Is there any possible way of converting the code so the carousel can work in AS3?
Below is the code for the AS2 carousel:
import mx.utils.Delegate;
var numOfItems:Number;
var radiusX:Number = 300;
var radiusY:Number = 75;
var centerX:Number = Stage.width / 2;
var centerY:Number = Stage.height / 2;
var speed:Number = 0.05;
var perspective:Number = 130;
var home:MovieClip = this;
var tooltip:MovieClip = this.attachMovie("tooltip","tooltip",10000);
tooltip._alpha = 0;
var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = function()
{
var nodes = this.firstChild.childNodes;
numOfItems = nodes.length;
for(var i=0;i<numOfItems;i++)
{
var t = home.attachMovie("item","item"+i,i+1);
t.angle = i * ((Math.PI*2)/numOfItems);
t.onEnterFrame = mover;
t.toolText = nodes[i].attributes.tooltip;
t.icon.inner.loadMovie(nodes[i].attributes.image);
t.r.inner.loadMovie(nodes[i].attributes.image);
t.icon.onRollOver = over;
t.icon.onRollOut = out;
t.icon.onRelease = released;
}
}
function over()
{
home.tooltip.tipText.text = this._parent.toolText;
home.tooltip._x = this._parent._x;
home.tooltip._y = this._parent._y - this._parent._height/2;
home.tooltip.onEnterFrame = Delegate.create(this,moveTip);
home.tooltip._alpha = 100;
}
function out()
{
delete home.tooltip.onEnterFrame;
home.tooltip._alpha = 0;
}
function released()
{
trace(this._parent.toolText);
}
function moveTip()
{
home.tooltip._x = this._parent._x;
home.tooltip._y = this._parent._y - this._parent._height/2;
}
xml.load("icons.xml");
function mover()
{
this._x = Math.cos(this.angle) * radiusX + centerX;
this._y = Math.sin(this.angle) * radiusY + centerY;
var s = (this._y - perspective) /(centerY+radiusY-perspective);
this._xscale = this._yscale = s*100;
this.angle += this._parent.speed;
this.swapDepths(Math.round(this._xscale) + 100);
}
this.onMouseMove = function()
{
speed = (this._xmouse-centerX)/2500;
}
When I add this code in AS3 I get the following error:
Scene 1, Layer 'Layer 1', Frame 1, Line 1 1172: Definition mx.utils:Delegate could not be found.
Scene 1, Layer 'Layer 1', Frame 1, Line 1 1172: Definition mx.utils:Delegate could not be found.
Scene 1, Layer 'Layer 1', Frame 1, Line 41 1120: Access of undefined property Delegate.
Scene 1, Layer 'Layer 1', Frame 1, Line 6 1119: Access of possibly undefined property width through a reference with static type Class.
Scene 1, Layer 'Layer 1', Frame 1, Line 7 1119: Access of possibly undefined property height through a reference with static type Class.
I'm quite new to AS2 and AS3 but after some research I understand that import mx.utils.Delegate; is no longer need in AS3 as it already has delegate and they are already built in so in the code so I delete the delegate which are line 1 and line 41 and got two errors:
Scene 1, Layer 'Layer 1', Frame 1, Line 6 1119: Access of possibly undefined property width through a reference with static type Class.
Scene 1, Layer 'Layer 1', Frame 1, Line 7 1119: Access of possibly undefined property height through a reference with static type Class.
Now I cant figure out what to do so can someone help me convert this code from AS2 to AS3?
You have quite a few things to address here:
Your mouse events need to be changed to as3 calls
t.icon.onRollOver = over, in as3 looks more like t.icon.addEventListener(MouseEvent.ROLL_OVER, over);
attachMovie is no longer used in as3.
you need to export for actionscript the movie you want to get from the library with a unique class name, then use new someName(); to create it. Then it must be added to the display list with addChild
onEnterFrame is not used in as3, you need to create an enterframe event more like this: **addEventListener(Event.ENTER_FRAME, someFunction);
delegate is not used in as3.
flags on _x, _y, _parent, _alpha etc have been removed in as3. just use x,y, parent, alpha etc.
swapDepths has been removed from as3, You need to use the display list to add/remove/swap levels.
sounds like you might need to study up a little on as3 before you can properly tackle this one! try checking out this link for comparisons between as2 and as3 functionality.
http://www.actionscriptcheatsheet.com/downloads/as3cs_migration.pdf