Events On Drawing..
hi, i want to create a movie clip in which a user can draw a filled rectangle. after creating a rectangle if the user clicks on the rectangle some events can be triggered. how can i do that. please help me with code. i have created the movieClip in which user can draw but i am unable to catch the events of drawn rectangle.
Faraz
FlashKit > Flash Help > Flash ActionScript
Posted on: 12-27-2006, 08:18 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Register Classes - Mc Events Vs Button Events
I'm experimenting with register classes today, and wasn't careful typing the code with only button events for my custom movie clip class.
First I wrote
Code:
CustomClass.prototype.onMouseDown = function(){
this.gotoAndStop("blue");
}// end onMouseDown
Then all the mc-buttons in my movie went to the blue state. (.fla provided)
When I realised the error, I corrected it, and now it works.
I just don't understand what happened.
Do Movie Clip events turn out to be class methods (don't know what to call it in Java script, only used to Java), while button events stay instance events??
Hope somebody have the time - it's not about life and death, but it would be really nice to know how these things work.
Drawing An Outline Of An Object In Flash And Then Animating The Drawing?
I wish to draw an outline of an object in flash? bit by bit a piece of the outline is drawn until the outline is completed, once this has finished then object then appears and the outline disppears (this part I can manage).
I do not know where to begin? So may need a lot of direction on this one.
Scrolling Drawing Board? Drawing Without Moving The Mouse
Hello, I'm new to this board and kind of a flash newbie so you could probably help me out.
What I'm trying to build is what you could call a scrolling drawing board - just like a drawing board but when the mouse comes close to the edge of the window, it scrolls and lets you continue your drawing.
I have no problem creating a drawing board with API, but i can't make it scroll. Usually when i want to scroll a background image i make it move along with the mouse when the cursor is near the edge of the window (for example, if the mouse's coordinates are above a certain number, the background image starts moving in one direction so it "scrolls" in the other direction).
So i wanted to do this with the movieclip of the drawing in a drawing board (make it move according to mouse's coordinates near the edge of the window), but when i scroll i have to stop the mouse at the edge of the window because i cant go any further :p so the drawing moves but it stops drawing. Or maybe what i need is some way to draw even when the mouse is not moving. Is that possible?
I'm sorry it may seem a bit confused (moreover english isnt my native langage :p), I'll try to post an example later. In the meantime, if any of you see how i can do that ... thanks
Drawing Board With Specific Section For Drawing
Ive made myself a drawing board in flash, but the problem is that i can draw over anything on the stage and I want to have a specific canvas for drawing.
I tried creating a separate MC and pasting the code there but it didnt help although i have no idea why. Any ideas?
Respond To Mouse Events Inside A Movieclip That Has Mouse Events...
I have a main MC that has a couple of mouse events associated with it (onPress mainly). There are also MC's inside this main MC that have Mouse events associated to them (onPress, onMouseMove, onRelease). The child MCs don't seem to get the mouse events (which makes sense, the parent is taking over the event)...how can I make this work? I don't want to have to delete and recreate the event handlers like 900 times as its not efficient...there has to be a better way.
Drawing Scripts For A Drawing Program
Need help with reference scripts for a simple drawing program. I'd like the user to be able to select different tools (circle, square, pencil, paint brush), change the color of the fill, and erase or reset the screen. Can anyone refer me to the right place?
Drawing A Soft Mask... Drawing Api?
Hello everyone, (almost) first post here
I'm creating a, quite original flash website (meh... not my idea in fact, I'm only the flasher!), in wich you're in a car, sitting on the passenger side, and you're looking outside to see the contents coming on the road.
It rains.
A lot.
So the windowseat is "fogged" (how can I say that...???) and while you're loading the content you actually can draw on the glass with your.. err... finger (mouse!), like how your friends usually do in your car when you really don't want their fingerprints all over your car glass
Ok, easy way to do that:
1 - attachmovie
you actually duplicate a circle, give it some randomness in blurring and size so it looks irregular and place it right under your mouse.
Good, it works... but when you move fast, it just leaves a blank spaces between clip and clip...
Hey... that's not fair...
2 - drawing api
Oh my god... I can't make a mask with a simple line, so I should draw a shape while moving the mouse.
The point is... HOW???
I dunno if there's a better way to do that, but that's the only one in my mind now.
Actually the drawn clip should also be blurred a little bit (1 or 2 percent) wich is not a problem since you can easily blur the container.
But now the real point is: how do I draw like that with the beginfill?!?!?
Note: I uploaded the fla so you can have an idea on how it looks...
Help Needed In AS3 Drawing Board ( With Drawing Api)
Hi all,
I'm doing a flash application with flash cs3 actionscript3. I tried with as2.
Now I am facing difficulty in doing it in AS3.
the application includes:-
all the vector or images should be editable means scale rotate color change etc.
draw line -
draw rectangle -
circle
input text.
curve with node points
if anyone have any tutorials or any resourse please post here.
thanks inadvance
Harish
Can Events Trigger Other Events?
Hello brothers and sisters of the Nets most helpful community!
I am going insane in the membrane trying to get my custom cursor to work in my scene. I have successfully completed many tutorials about how to do this in AS3 (the danielmclaren.net solution was particularly helpful) and have scoured this forum a bit for info, and (gasp) also read through a bunch of stuff on live docs. But, alas, I cannot understand why I cannot get the custom mouse (cursor) to work in my file. It works like a charm until I try hammering it into my scene.
I believe that the problem has something to do with with too many events being fired off at the same time and (possibly) my not removing them at opportune times. Or, maybe my coding style is not so elegant? Anyway, the FLA (with easy-to-read structure and commenting) can be downloaded here since I am not certain which part of my code is causing the custom cursor not to work. With all the comments, it should not be too difficult (I hope) to see what it is I am trying to do.
Any feedback would, as always, be most appreciated.
Download_FLA
Regards,
-john
[MX04] "Drawing" Line Effect Using Drawing API
So i've got a basic drawing using the drawing API ala:
myLine = this.createEmptyMovieClip("newLine", 1);
myLine.lineStyle(3, 0x000000, 100);
myLine.moveTo(0,0);
myLine.lineTo(100,0);
myLine.lineTo(100,100);...etc
Now is there a way to have flash animate the drawing of the lines like a map from an Indiana Jones movie?
Thanks!
Drawing Api Drawing Saving
ok - say i have made a swf where you can draw, with possible color change and different brush size, and i want to somehow save my drawing (in a database)
so i figured every little line that is drawn on enter frame has 6 values - start x, start y, end x, end y, color and size.
approximately - first 4 are 3 numbers, color is 6 numbers and size is 2 numbers length, so its 4*3+6+2=20 numbers for one little line
the framerate of the movie is 100fp/s so getting the maximum smoothness of the drawing, so one little line is drawn in 1/100 of a second, and in a second i have to save 20*100=2000 numbers.
a symbol is 8 bytes, so 2000*8=16000 bytes (/1024~15,5kb) - in a second!
so if you draw for a minute - its 16000*60=960'000 bytes (/1024~937,5kb~1mb) in a minute!
and my question is how to save a drawing to a database different way then im thinking, to me this seems the only way...
1mb per minute of drawing seems kinda lame for me and noone will want to wait till it loads up
Drawing Api Drawing Saving
ok - say i have made a swf where you can draw, with possible color change and different brush size, and i want to somehow save my drawing (in a database)
so i figured every little line that is drawn on enter frame has 6 values - start x, start y, end x, end y, color and size.
approximately - first 4 are 3 numbers, color is 6 numbers and size is 2 numbers length, so its 4*3+6+2=20 numbers for one little line
the framerate of the movie is 100fp/s so getting the maximum smoothness of the drawing, so one little line is drawn in 1/100 of a second, and in a second i have to save 20*100=2000 numbers.
a symbol is 8 bytes, so 2000*8=16000 bytes (/1024~15,5kb) - in a second!
so if you draw for a minute - its 16000*60=960'000 bytes (/1024~937,5kb~1mb) in a minute!
and my question is how to save a drawing to a database different way then im thinking, to me this seems the only way...
1mb per minute of drawing seems kinda lame for me and noone will want to wait till it loads up
Drawing API - A Line Drawing Itself
I can draw a simple line with the drawing API and I'm able to place it on the stage where I want to but I'm trying to have the line draw itself between x=0 y=0 and x=600 y=400.
Any pointers on how to take that on?
t/y
Cant Tell When Merge Drawing Model Vs. Object Drawing Model
I keep drawing shapes on the same layer, overlapping them, and then trying to delete one of the shapes to cut a shape out of the first. This does not work automatically as Help says it does, I have to go to "Modify > Combine Objects > Union" to merge them, THEN I can cut my shape out. When is this supposed to occur "automatically"? How am I supposed to know what mode I'm in?
Cant Tell When Merge Drawing Model Vs. Object Drawing Model
I keep drawing shapes on the same layer, overlapping them, and then trying to
delete one of the shapes to cut a shape out of the first. This does not work
automatically as Help says it does, I have to go to "Modify > Combine Objects >
Union" to merge them, THEN I can cut my shape out. When is this supposed to
occur "automatically"? How am I supposed to know what mode I'm in?
Object Drawing Model / Merge Drawing Model
Recently I reinstalled Macromedia Flash 8, but then it was installed with the "Merge Drawing Model" instead of the "Object Drawing Model". How do I change this?
I've tried to read this, but it doesn't say exactly what to do;
http://livedocs.adobe.com/flash/8/ma...=00000486.html
Thanks
-JPAG
Key Events?
ok people i am using the the number keys 1, 2, 3 and 4 to navigate through my site. im also using using multiple swf's on multiple levels all loaded into one main movie. i put a button in my navigation level that has the actions for keypress 1,2,3,4. now im loading my guestbook onto a higher level, but if you press 1,2,3,4 you get taken to a different part of my site. is there anyway to set the focus of these keys or make them stop while that level is loaded???
confuesd? me 2
check it out for your self
http://www.sub7designs.com/test/jon.html
press 4 then try to enter a number into gbook and you see what i mean
thanks
Key Events
hallo,
is it possible to catch 2 key events at once in flash 4?
I've got a 2-player flash pong. During one player presses a key to move
his paddle, the other player can't move his paddle because flash doesn't
catch the other key event.
I've got 2 invisible buttons (one for each paddle) to catch the key
events.
Thanks in advance,
ute
Events
Why the f*ck doesnt this work:
function test() {
this.callback();
}
test.callback = function(){
trace("callback");
}
test();
thank you all.
::mate::
Can Do Any Two, But Not Three Events Together
What should happen:
When a user clicks a nav button, the main movie should advance to a frame label with anchor. Next, an already loaded movie should play at frame 2, and lastly a different movie should load to a movie clip target.
The problem:
I can get the main movie to advance to the correct label and either load a movie or play the already loaded other movie. But not do both.
The code:
-- Nav button
on (release) {
gotoAndplay("labelnamedX");
}
-- At frame label on action layer
_root.alreadyloadedmovie.gotoandplay(2);
loadMovie("NewMovieToTargetMC.swf", "_root.holder");
stop();
--Thanks in advance
Greg
Key Events
Is it possible handle key events inside classes?
If so, how to addListener to the Key object inside a class?
Events
I am trying to set up a simple generic event handling class but its not working for some reason.
This is the Object.as file:
Code:
Object.prototype.startListeners = function(propName) {
this.watch(propName, this.propSet);
};
Object.prototype.addListener = function(listener) {
//check to see if the listeners stack exists
//and create it if it doesnt
if (this.listeners == undefined) {
this.listeners = new Array();
}
this.listeners.push(listener);
};
Object.prototype.removeListener = function(listener) {
for (var e = 0; e<this.listener.length; e++) {
if (this.listeners[e] == listener) {
this.listeners.splice(e, 1);
break;
}
}
};
Object.prototype.propSet = function(prop, oldVal, newVal) {
for (var e = 0; e<this.listeners; e++) {
//trace(e);
this.listeners[e]["on"+prop+"Change"](oldVal, newVal);
}
//return newVal so it is assigned
return newVal;
};
and in the fla I have made a class and tried to watch the returnval property for change. That code is:
Code:
_global.dh = function(val) {
this.returnVal = val;
};
obj = new Object();
obj.onReturnValChange = function(oldVal, newVal) {
trace("returnVal has changed from "+oldVal+" to "+newVal);
};
aDataHandler = new dh(10);
//add obj_listener as a listener
aDataHandler.addListener(obj);
//start listening for returnVal
aDataHandler.startListeners("returnVal");
//test event handler
aDataHandler.returnVal = 5;
aDataHandler.returnVal = 53;
why oh why it isnt working - I do not know!!
Please help
Events
hello there. i read some articles about AsBroadcaster and EventDispatcher class, but...i did not get hte point.
for example i have class MenuItem, and class
ToolTip(there are many of the MenuItems and only one ToolTip) how can i create the Event for the ToolTip - "itemRolledOver"(for example) ?
PS i know that i can use onRollOver for the MenuItem class but i want to learn this stuff=)
thanks in advance
Help With Key Events
One thing I just can't seem to figure out no matter how much reading or testing are the key events, listeners, press, keyUP, keyDOWN. There are 40 different ways to do something with a keypress, and I'd like to learn some. I animated a little guy walking left, right, standing, jumping. I want to use the arrow keys to get him to go through these states. I need for when you hold down left for him to animate the walking left animation and when you let go to go back to standing or go to whatever animation is neccessary; determined by the keys. I've got some rigged way of doing it but it glitch's and looks bad. Could someone try explaining what a good way is to register key press, key down, key up so that I can use it? THANK YOU!
[F8]
Where Are The Events?
I am trying to build a little Object-Oriented video player (for files, not server).
I have set up:
- a NetConnection object with .connect(null);
- a NetStream object within the connection, and called .play(url);
- a Video object, to display the stream;
I have put handlers to handle:
- NetConnection NetStatus events;
- NetStream NetStatus events;
- NetStream onMetaData events (through a custom class as client);
- NetStream onPlayStatus event (through a custom class as client);
Well, playing around with commands, I figured that VERY FEW events actually get dispatched.
Basically, when calling .pause() or .close(), on the stream, no event is fired.
When the file reaches the end, I see the following events being fired, and the movie plays over again:
NetStream.Buffer.Empty;
NetStream.Buffer.Flush;
NetStream.Play.Stop;
NetStream.Seek.Notify;
NetStream.Buffer.Empty;
NetStream.Buffer.Full;
What the hell is going on????
Why don't I see ANY pause/play event?
Why don't I see ANY complete event?
Why!!??????
Why Should I Use Events?
Why should I use events?
I mean, in order to use events, I have to 1. setup an event dispatcher, 2.add an event listener to an object and 3. have a listener function set up.
Could I not achieve the same thing by just calling a function in whichever object I need to?
What is the benefit? Maybe I'm missing the point....
Anyone care to enlighten me? Cheers!
Why Use Events?
everything i read about events is how to use them, but i still don't know why you would want to. cant you just put in the onEnterFrame event:
PHP Code:
if (your event)
{
//your action
}
My Own Events
Hi.
I want to define events for my classes, so when I use these classes I will be able to use the addEventListener.
but how?
thx.
I don´t know if I´m clear.
IE And Key Events
anybody notice that Internet Explorer (at least the new version) hijacks key down presses so that the entire page scrolls when you press key down or up?
this problem, as far as i can tell, is associated with wmode-- when this is set to 'opaque' there is definitely a speed gain--however, i've noticed an annoying habit of Internet Explorer's (Don't really use explorer much so don't know if this has always been the case or if just the most recent IE) --whenever I use IE to play a flash game with wmode='opaque', the up and down arrow keys scroll the entire web page! does anyone know a solution to this issue other than opening up a pop up window, which does work, but which is not ideal for me.
am i missing anything? is there a way to have wmode=opaque and not have this annoying scroll effect in IE?
AS3 Events
Can someone show how I can listen event dispatched from class in my main application ?
I'm using mooska's mysql AS3 library to get data but main application doesn't see when data is loaded in class file.
I tried dispatchEvent(new Event("gotData")) in class file when the data is stored into arraycollection.
Help With Events
Hi! This is my first time posting here. I am taking Flash 1 at the local college and even my instructor is stumped as to why I am having problems with this file. I hoped maybe some of you Gurus could help me with some ideas.
I have one FLA file. On the main timeline is 2 movie clips. One of the movie clips is in perfect working order and has no issues. The other is a simple movie clip with frame labels and a single button on it to load a GIF image. There are 12 frame labels on this movie clip, each showing a different picture at that frame and on each of those the button viewLarger has been placed and given an instance name of large1, large2, large3, etc. depending on what picture it is to load.
mediumMovie is the name of the movie clip that the buttons are in.
this.mediumMovie.large1.addEventListener(MouseEven t.CLICK, largePics);
this.mediumMovie.large2.addEventListener(MouseEven t.CLICK, largePics);
The button should be able to show that specific picture in an external window. But nothing I am doing is working.
function largePics(event:MouseEvent):void
{
var loadLargePic:URLRequest = new URLRequest(event.target.name + ".gif" );
navigateToURL(loadLargePic, "_blank");
}
All of this code is on the main timeline in an "actions" layer to keep all my actionscript in one place.
I added a trace into the function and apparently the button click is never even entering the function at all. Please remember that I am in this class and I have only known flash for a few months. I am far, far from knowing all the tricks and ins and outs of AS3. Any suggestions would be greatly appreciated though.
=) Thanks in advance! Pamela
As3 Events?
Quote:
ok i'm more of a as2 programmer. i understand how to code in as2 rather well.
recently i've been learning as3 and i've learned how to code all things without having to code on movieclips and declaring variables. and some of the statements i should be using but one thing i can't seem to do is the dam events.
see in as2 it was simple:
ActionScript Code:
this.onEnterFrame = function(){
// do code
}
but in as3 they changed it so i tried the code structure the help suggested but it didn't work. so i'm now all out of ideas. can anyone help?
this has been solved now. anyone looking for the solution, should read the article in the second post of the topic. then from there they can see my example in post 6 of the topic.
MC Events
hi everyone. I know that I can make an event for a button like this on the main timeline instead of the traditional way:
ActionScript Code:
_root.myButton.onPress = function() {
trace("this is my statement");
}
but how can you achieve the same thing for mc's. Specially for the data, and load events? Thank you.
Events Go Through The Mc
I have a mc with a white background drawn with beginFill and endFill. The mc is sometimes over another similar mc that contains a button. Now if click on the white backround the button beneath the mc gets the click.
How do I get rid of this?
I Tried to add a custom invisible hitarea but that didn't work.
1 Btn 2 Events In AS3
I'm trying to create a conditional statement where when I click a button it will go to one frame, play and then once the clip is triggered to stop it will go to another frame and play. I can figure out how to make a button go to one frame and play but I can't figure out how to actionscript 3 it to then go the next frame one this is completed. I basically want to create a site that will operate like this:
http://www.deutschinc.com/
I think I can handle the if construction to make the right clip leave the scene.
Please help!
Thanks
2 Events
im trying to get this thing to run two events at a time like this
onClipEvent(keyUp){
onClipEvent(enterFrame){
}
}
like that but with an action in the middle but it says theres an error in it.
does anyone know how to do that
Key Events Help
would you use a string to have AS recognise a whole word instead of the first letter of that word??
also once i have a MC appearing after a key has been pressed how do i allow the user to type in the input boxes without it disappearing again??
here is my code so far:
Code:
stop();
var oKeyListener:Object = new Object();
oKeyListener.onKeyDown = function():Void {
if (Key.getAscii() == login_txt.text.charCodeAt(0)) {
_root.login_screen._alpha = 100;
} else {
_root.login_screen._alpha = 0;
}
};
Key.addListener(oKeyListener);
that code is on the first frame.
but i also want the user to have the option of when they press any other key the window will disappear but if its open they have the option to type in it.
is this possible?
thanks peeps
Key Down Events
hi guys
i need to track the keyboard events in flash..right now if i press ctrl +shift + right arrow... i need some actions to take place .say trace("keyDown") .can some body pls guide.
Events.
Iv'e done events and things in my new classes just perfectly.
But wth is up with trying to do this in a frame?
I basically want to have some data initialized (before anything else) and uninitialized (after everything else), or rather how I used onLoad and onUnLoad (among others like mouseDown and mouseUp) for the main stage (or the frame I'm working on sort of thing).
Also, why on earth did these morons give us a constructor event without a deconstructor event? Imean fair enough if it is named differently, but why..... it makes no sense lol.
[AS3] Events
I whipped something up really quick and wanted to know if someone could help me. Right now I built a context menu class that just pulls its information from a XML file. That works fine and I also built a MainNav class that I have linked to a MC on my stage.
Everything works fine my question is since I have my MainNav class linked to the MC on the stage how can I access it from the Main class? Because I would eventually like to have it setup so that when you view the swf the preloader does it thing then the nav will tween in like it currently does. As of right now it tweens from the start but I would like to add a listener or something to that extent so that once the xml/preloader is done loading then to this.
FYI: In your class path you will have to have it like ../classes to work with my folder structure.
Thanks
1 Btn-different Events
Hi
Need some help with this:
PHP Code:
//Speed varsmin_speed = 1;max_speed = 6;beschleunigung = 1.03;speed = 1.6;//Clips posmc1._x = 0;mc2._x = mc1.width;mc3._x = 2*mc2.width;mc4._x = 3*mc1.width; //Changepointchange_point = -(2*mc1._width);//Bool varsvar drive:Boolean;var acceleration:Boolean;var deceleration:Boolean; //_______________________________________________________________________________//_______________________________________________________________________________//Deceleration and stopfunction anhalten() {speed = Math.max(speed, min_speed);this.onEnterFrame = function() {speed>min_speed ? speed /= beschleunigung : speed=min_speed=0;move_Clips();};}//_______________________________________________________________________________//_______________________________________________________________________________//Default drivefunction fahren() {this.onEnterFrame = function() {speed = 6;move_Clips();};}//_______________________________________________________________________________//_______________________________________________________________________________//Restart with acceleration function anfahren() {speed = Math.max(speed, min_speed);this.onEnterFrame = function() { speed<max_speed ? speed *= beschleunigung : speed=max_speed;move_Clips();};}//_______________________________________________________________________________//_______________________________________________________________________________//Clips loopfunction move_Clips() {for (var i = 1; i<=4; i++) {var myClips = this["mc"+i];myClips.filters=new Array(new flash.filters.BlurFilter(2,0,2))myClips._x -= speed;if (myClips._x<=change_point) {myClips._x += this._width;}}}//_______________________________________________________________________________//_______________________________________________________________________________//Btn eventsmy_btn.onRelease = function() {if () {trace(deceleration.valueOf());this.gotoAndStop(2);anhalten();test_Txt.text = "ANHALTEN";} else {trace(acceleration.valueOf());this.gotoAndStop(1);anfahren();test_Txt.text = "ANFAHREN";}};//_______________________________________________________________________________//_______________________________________________________________________________fahren();//default drive
What I want to achieve is that the btn can stop the default drive by starting the function anhalten and then it should be able to restart with the function anfahren...
I think this should go with if/else and bool-vars, but I could not make it work.
Thanks for any help.
Regarding The Events
Hi
i have created a clip with some animation. i hav a button. by clicking it the clip has to be removed. so i hav written it on release event of the button. but whts the problem is the clip has to be removed only when its full animation is over till that we hav to wait in on release event. is there any function to delay the event handler such that the animation gets over by some time and then it is removed from the screen.
awaiting for reply,
Thank you
Events
I have 3 buttons , each going calling a different movie clip.
Lets say for example, I have Movie clip 1 on the screen but I want move 2 to show
I click button 2 which calls movie clip 2 to zoom into the screen. but before movie clip 2 can zoom in, movie clip 1 needs to zoom out.
How do I set a condition to tell the active movieclip to finish before displaying the new move clip
Key Down Events
Hey guys, this is my first post here so... hi
Anyway... im currently making a side scrolling space game. Im completley stuck with trying to get the weapon to 'charge'.
I have the basic fire button on CONTROL, this works fine, but what i want is, if the CONTROL button is held down the weapon stops firing and charges, then releases a different fire graphic depending on how long the button is held down for.
here is the basic code i have to far
Spaceship movie clip:
onClipEvent(load){
_root.firea._visible=false;
fireCounter=1;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.CONTROL)) {
fireCounter++;
_root.firea.duplicateMovieClip( "firea"+fireCounter, fireCounter );
_root["firea"+fireCounter]._visible=true;
}
Regards
Scott.
MVC - Where Do Events Go?
I'm tackling AS3 for the first time and also trying to, at the same time, get a basic handle on the MVC pattern. I've never used a design pattern so I might be biting off more than I can chew : ( Anyways, I have this question:
My understanding of MVC is that:
Model: core logic and state are in this class; it's also the 'document class' typically?
View: graphical assets are rendered via this class
Controller: event handling
I am putting together a game as my first try at AS3 and MVC. Don't laugh, but it's a simple idea (I think) that my toddlers will enjoy. The game is called "Find Daddy!". The game will have a grid consisting of 5 rows of 5 images. Each image will be able to clicked on and, once clicked on, will be swapped with another image. The goal is basically for the player (my toddlers) to click on each picture and try to find the one that reveals a picture of me as fast as possible (I will add a timer and a 'score' will be generated at the end depending on how quickly they find me). Yes, it's dumb, but if you have/had/ever will have kids you might understand : ) Mainly though it gets me working on something real to learn AS3.
My game has 3 classes:
View.as
Model.as
Controller.as
The Model.as is my document class. I plan on putting all of the images and graphical assets in the fla's library eventually. For now, I am working out simple problems though, like buttons and event handling. I never did grasp this in AS2. In my View class I have:
Code:
private function createButtons():void
{
//new game button - make sure to add it to the library in IDE first!
newGameButton = new Button();
newGameButton.x = 50;
newGameButton.label = "New Game";
newGameButton.addEventListener(MouseEvent.CLICK, newGameHandler);
graphicsContainer.addChild(newGameButton);
}
private function newGameHandler(e:MouseEvent):void
{
trace("new game button clicked.");
}
When compiled and run the game displays a simple background 'game board' that I have in the fla's library, and adds this button to the display list. When I click on it, it works as expected by tracing out the "new game button clicked" text in the output panel.
But originally I tried putting the newGameButton.addEventListener and the newGameHandler() code in the Controller class. Am I misunderstanding the MVC pattern, or am I just not understanding how to do it syntactically? When I have the following code in my Controller class's constructor:
Code:
newGameButton.addEventListener(MouseEvent.CLICK, newGameHandler);
private function newGameHandler(e:MouseEvent):void
{
trace("new game button clicked.");
}
I get a compile-time error basically saying that I'm trying to access a newGameButton that it knows nothing about. Help!
AS3 Events
Hello everyone,
I'm learning AS3 now (no previous experience with AS). I've noticed at most of the examples out there that the sequencing of code lines in AS3 that makes little to no sense to me (compared to my knowledge in Java and other OO code with listeners). For example:
Code:
var myRequest:URLRequest = new URLRequest("large_image.jpg");
var myLoader:Loader = new Loader();
myLoader.load(myRequest);
myLoader.contentLoaderInfo.addEventListener(Event.OPEN,showPreloader);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,showProgress);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showContent);
As you can see, if the sequence of execution is in the sequence of the lines, the load event starts before we add the listeners to it. Now lets say that the event itself is VERY short, we will lost the events right? In other languages you usually (not always) register the event before the action started.
Any thoughts?
I appreciate any comment and information on how Flash will execute the code if it is different then normal sequencing.
Thank you
Please Help Me With Events
Hello Everyone.
I am having some issues with a dropdown type of navigation that I developed in Flash. I recently posted about making a movieClip visible for only a certain amount of time, but I figured that might not be my best option.
Please bear with my explanation. I tried to make it as clear as possible.
I have 6 main navigation buttons. Two of those when rolled over invoke their own menu (which is a movieClip with buttons within the clip) to appear below the button. One of the two has a sub menu (again, a movieClip with buttons within the clip) for the menu.
Each of the main navigation buttons are just that, a button. When I mouse over the ones with the menu's appear because I put an event
Code:
menu._visible = true;
in the button. The same is done for the menu that has the sub menu. The buttons in the movieClip (the menu for the main button) has a the same type of call to the sub menu movieClip
Code:
submenu._visible = true;
Now that I have explained that, I'll describe my problem:
When I mouse off of the main navigation button, the menu movieClip disappears by my use of the
Code:
menu._visible = false;
This is great if I intend to go to another main navigation button, but bad if I want to roll onto my menu that appeared, because if I roll off of the main navigation button, the menu that I'm trying to rollOver disappears. The same happens with my sub menu.
I know this is a lot of explanation without the actual file, but if anyone has any advice I'm all ears!!!
Thanks
Brian
Two Of The Same OnClip Events?
okay, i'm a rookie. i got some code from different scripters to make these small movie clips move around in a 250x60 area. (WHICH IS by the way - not working). this may be a dumb question, but is it possible to have an 'onClipEvent (load)' with another one right next to it? The same goes for 'onClipEvent (enterFrame)'. Do these have to be combined?
i've got a headache.
---------------------------
onClipEvent (load) {
stop_me = false;
_x = Math.random()*250;
_y = Math.random()*60;
xspeed = 2*(1-2*Math.round(Math.random()));
xspeed = 2 or -2;
yspeed = (1-2*Math.round(Math.random()));
// yspeed = 1 or -1
}
onClipEvent (load) {
my_name = _name.substring(2, _name.length-1);
// get the number of the MC, 1 if it's MC1, etc...
total = 8;
// assuming there are 8 MC's floating around, MC1 up to MC8
function testHit () {
turnre = false;
// set turnre to false : no hits
for (i=1; i<=total; i++) {
if (hitTest(_root["MC"+i])) {
turnre = true;
// it's hit another MC
break;
// break out of loop since there's a hit
}
}
return turnre;
}
}
onClipEvent (enterFrame) {
if (testHit()) {
xspeed *= -1;
// turn direction around
yspeed *= -1;
}
}
onClipEvent (enterFrame) {
if (!stop_me) {
_me_x += xspeed;
_y += yspeed;
if (_x>=0) {
_x = 0;
xspeed *= -1;
} else if (_x<=250) {
_x = 250;
xspeed *= -1;
}
if (_y>=0) {
_y = 0;
yspeed *= -1;
} else if (_y<=60) {
_y = 60;
yspeed *= -1;
}
}
}
|