I am having trouble getting all my images to load for my canvas project at school. I can get the red dot to load and follow the mouse like its supposed to, but the rest does not want to work. Do I have a syntax error or am I missing a line of code? Any help would be greatly appreciated. Here is a link to the playcode:
https://playcode.io/599039/
Related
I'm trying to make a game for a school assignment and I'm trying to make a button that, for now, will just trace that it has been clicked. However, anytime I try to run it it says "1046: Type was not found or was not a compile-time constant: MouseEvent." Here is the code:
Image of part of the code
(apparently I can't embed an image so I hope this works...)
This is in the button's code, not the stage.
I've tried figuring it out and looking up how to solve this however can't find the answer. I'm not sure what the cause is or how to solve it. Can anyone help me?
I've been playing around with HTML5 and canvas and sprites and I've managed to get myself a bit stumped. I was wonderring if there was anyone out there with just a bit more experience than me who could help me 'tune' this (and also make it work).
I've got all the code up on GitHub https://github.com/AlexChesser/jsSprite and have put a live demo up over here http://chesser.ca/jsSprite
What you can see from Test 01 and 02 is that I'm able to send the Minotaur directly to the on-page canvas, I'm able to animate the Minotaur on the canvas... but when I try to create the Minotaur and add it to another canvas - I'm getting a blank screen.
(attempting to implement https://github.com/AlexChesser/jsSprite/blob/master/03-animated_minotaur_on_canvas.php)
I know it must be something small and sill that I'm doing wrong here, but I've been staring at it for hours and I can't track down the problem.
I thought I'd try posting up here to see if there's anyone who can see it 'in one go' AND to maybe let me know if there's anything I can do better.
If you're interested in getting a little further under the hood on this stuff, the lion's share of the code for this is coming from a Blog post http://www.johnegraham2.com/web-technology/html-5-canvas-tag-sprite-animation-demo/
Anyways, maybe it's one of those things that "comes to you" once you've walked away from the problem for a little bit. Fingers crossed I can either figure it out or someone out ther ecan give me that little push in the right direction.
Thanks!
:)
I just stepped through your code.
MainContext.drawImage(m.canvas, 0, 0, m.width, m.height);
is occuring before drawFrame gets called because the image isn't ready yet.
So the mainContext.drawImage is drawing a canvas that has nothing painted on it yet.
Then the Sprite's canvas is loaded and ready to go, but its too late!
For confirmation, you can call MainContext.drawImage(m.canvas, 0, 0, m.width, m.height); in the browser console and you will see the minotaur appear.
As Simon Sarris said, you are drawing the canvas too soon. What you'll need to do is either loop until the sprite is ready, or add a callback to your sprite that is called after it draws.
You already have a function attached to the image's onload event, you should be okay to do something similar for the whole sprite.
I'm trying to get a hover effect for displaying information against points on a line chart using gRaphael. I've got a basic version working here http://www.matthewhollings.co.uk/svg/raphael-line-test.html but there seems to be an offset against the point that the hover responds to when two lines are close together. Does anyone know how I can fix this so that each point responds when the mouse pointer is closest?
Also, I'm trying to make the line chart look more like the one on the raphael website, where the hover flag contains both the x and y value of the point and is animated along the path. Any help with that would be greatly appreciated!
Many thanks in advance,
Matt
I'm looking to place an image (object) on top of the other object (default video player in Flex 4), any suggestions are most welcome. Do we've to use canvas? can I do it without using canvas? An example would be greatly appreciated, thanks.
Regards
You can have a look at this tutorial for more info:
http://www.republicofcode.com/tutorials/flash/as3displaylist/
but adding an object on top of another one , is as simple as this
addChild(child1);
addChild(child2);
basically the first object added is at the bottom of your stack. now if the object you want placed under was added after the first one. you still can do this:
addChild(child2);
addChildAt(child1, 0 );
there are, of course ,more options to manipulate the children positions but you should find what you need in the tutorial above.
Oops , sorry the word Canvas , got me confused. I thought you were trying to do this within Flex. Do you mean to say you want to do that in HTML. If you do, please retag your question, because it wouldn't really be a flash issue .
Hope it helps ;)
I am quite new to AS3 and I have never worked with classes, so I am encountering a couple of problems.
I'd like to center a movieclip, have it so that it doesn't scale. And then I'd like to add a background color that stays there no matter how I scale the browser.
Can someone please explain me this in babysteps? Since I don't know how to implement a class and make it work with my fla.
Thank you so much!
J.
If I've followed you correctly, you want to have your swf file in the centre of a webpage, to change the background colour, and to stop the swf from stretching if you drag the boundaries of the web browser around?
If so, your question is a more HTML related, as none of that can be accomplished through ActionScript. If what you want to do is position your swf inside an HTML file correctly, you can make Flash export the HTML file for you (assuming you're using the Flash IDE).
Here's a link that'll guide you through the process of doing that, it's very clearly written: http://www.w3schools.com/flash/flash_inhtml.asp
To change your web page's background colour, see this site: http://www.tizag.com/htmlT/bgcolor.php
Once you've got that HTML file exported from Flash, you can check how it will align your Flash swf to the rest of the webpage. Somewhere in the code should be something like align="left", and you can change that to centre, right, etc.
Hope that helps,
debu
to center it you can do:
var toCenterMc:MovieClip = new MovieClip();
toCenterMc.x = stage.stageWidth/2 - toCenterMc.width/2;
toCenterMc.y = stage.stageHeight/2 - toCenterMc.height/2;
backgroundcolor you can add with this tag (it has to be above the class header, that means the code line that says public class example extends exampleparent):
[SWF(backgroundColor="0xec9900")]