| Page 1 of 1 | [ 3 posts ] |
|
I've created a simple shape that I want to draw when a user presses the mouse button, when I'm getting the following error.
Quote: Uncaught TypeError: Cannot call method 'addToRedrawQueue' of undefined The code to draw the shape looks like this: Code: YUI().use('graphics', 'node', 'base', function(Y) { FC.PlayerIcon = Y.Base.create('playerIcon', Y.Shape, [], { _draw: function() { this.clear(); this.moveTo(0,0); this.lineTo(5,5); this.moveTo(0,5); this.lineTo(5,0); this.end(); } }, { // Static methods/properties ATTRS : Y.mix({ stroke: { weight: 2 }, color: "#fff" }, Y.Shape.ATTRS) }) }); and the following to set up an event : Code: Y.one('#canvas').on('click', function(e) { newThing = new FC.PlayerIcon({ x: e.pageX, y: e.pageY }); }); I've pasted the source for both files in full hereClick here to see the revision history on this Gist. |
|
In the Graphics module, shapes are typically created through the addShape method of Graphic instance.
http://yuilibrary.com/yui/docs/graphics/#creating-shapes That said, as of 3.5, I have added the ability to create shapes as standalone objects. It's tested but it has not been documented outside of some api documentation on a private method. I have filed a ticket to ensure this gets documented: http://yuilibrary.com/projects/yui3/ticket/2532393 When creating standalone shapes, you need to pass a node reference to the graphic attribute. (under the hood, the shape will create a graphic instance rendered into the node and then add the shape instance.) I have updated your example to render the shape into the #canvas element. Code: Y.one("#canvas").on("click", function(e) { var icon = new FC.PlayerIcon({ x: e.pageX, y: e.pageY, graphic: e.currentTarget }); }); In your custom class, I am not sure if you are trying to override the stroke attribute to have a default weight of 2 and default color of #fff or if you are trying have a stroke with a default weight of 2 and fill with a default color of #fff. Below is updated code to accomplish either. In both cases, I have updated the mix method with merge set to true so that you only override what is specified. Additionally, based on your _draw method, I have the ATTRS extending the ATTRS for Path. Path elements size based on the drawing operations while Shape elements are sized explicitly by the width/height attributes. stroke with default weight of 2 and default color of #fff Code: // Static methods/properties ATTRS : Y.mix({ stroke: { valueFn: function() { return { weight: 2, dashstyle: "none", color: "#fff", opacity: 1.0 }; } } }, Y.Path.ATTRS, false, false, null, 0, true) stroke with default weight of 2 and fill with default color of #fff Code: // Static methods/properties ATTRS : Y.mix({ stroke: { valueFn: function() { return { weight: 2, dashstyle: "none", color: "#000", opacity: 1.0 }; } }, fill: { valueFn: function() { return { color: "#fff", type: "solid", opacity: 1, cx: 0.5, cy: 0.5, fx: 0.5, fy: 0.5, r: 0.5 }; } } }, Y.Path.ATTRS, false, false, null, 0, true) Thanks, Tripp |
|
Brilliant thanks!
|
| Page 1 of 1 | [ 3 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group