How To Script Function Events
ok there seems to be no consistency in actionscript... apparently you have to delimit, define and callback to a function differently if it's in a frame or on a button or a movie? is this so?
im trying to experiment with the color transforms (penners) and haven't had any luck - i haven't had any luck doing much with actionscript except move the block - and even that i had to cut and paste the first 10 times - is there some basic rule of thumb that i'm missing? in most other scripting language, you define the function anywhere in the doc you want (within limits), define the arguements there or inline, and call it (often with as little as a single piece of syntax, = ) after any event... but from what i'm reading it matters where i define it and on what el i'm calling from AND to?
here's a bit of that script for ref:
Code: Color.prototype.setBrightOffset = function (offset) { var trans = new Object(); trans.rb = trans.gb = trans.bb = offset; this.setTransform(trans); } my questions are: 1. does that work in a frame, on a clip, neither/both? and why? 2. how do i call it, and what do i attach the callback to? 3. is object boolean in AS or are all variables considered strings? 4. how to get it to animate? my thought was put that ^^ in onenterframe in frame 1 of main timeline, then put in frame 1 of the symbols being tapped something like onclipevent or another onenterframe and nest rollovers and outs inside that with _root.setBrightOffset('255');
thanks, and dont mean to sound whiny i just can't get the hang of this language.
FlashKit > Flash Help > Flash ActionScript
Posted on: 06-02-2004, 06:46 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Specifying Same Function For 2 MC Events
My brain is giving out on this, I want to specify the same function for the onRelease and onReleaseOutside events of a MC.
Is this right?
code:
myMC.onRelease, myMC.onReleaseOutside = function() {
// do stuff
}
//or do I have to do the following?
myMC.onRelease = releaseFunc;
myMC.onReleaseOutside = releaseFunc;
function releaseFunc() {
// do stuff
}
Using Clip Events Within Function?
i am trying to create a "fader" function that gradually alpha's out a movie clip, when a flag is set to true.
The fader tested and working code on the movie clip is:
onClipEvent (enterFrame) {
if (_level0.doFader=="yes") {
if (this._alpha>0) {
this._alpha -= (100/12);
}
}
}
However, whenever I add it to a function I get the following error message:
Clip events are permitted only for movie clip instances
onClipEvent (enterFrame)
Can anyone suggest how to create a similiar end result or how to modify the code so I can insert it into a function.
The ideal end result would be a function I can call from the timeline and tell it what instance to fade out.
Thank you for your assistance.
Function For 2 Events Complete?
for the code:
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
is it possible to have it so that a function doesnt execute until 2 things are loaded or is the best way a simple tree function where you have
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
function loadXml
{
nextLoad.addEventListener(Event.COMPLETE, LoadXML2);
}
just wondering is all, thanks
Dan
One Function, Multiple Events
Hello. I'm writing a function that will be invoked by either a button press or a key press. Do I need duplicate functions...
Code:
function foo_A(event:MouseEvent)
function foo_B(event:KeyboardEvent)
or can I get away with
Code:
function foo(event:Event)
?? Many thanks.
Multiple Mouse Events In Function
Hi I have this code and it works
Code:
hslider.onRelease = function() {
this.stopDrag();
}
but I want to make it
hslider.onReleaseOutside, onRelease, onRollOut, onDragOut = function() {
this will not work, what is the correct syntax for these multiple mouse events in my function definition?
thanks
mark
Listening For 2 Events Before Triggering ONE Function
What is the best way to handle an object listening for 2 events before executing ONE function? (and I don't want the function to execute twice)
In my case, I want a request to be made for some data to load at the same time that an exit animation is playing. Before I want my intro animation to occur, I need the data to load AND the exit animation to be done! Two separate events! I know I could make it so the data request is not made UNTIL the exit animation is done, but that seems wasteful. Why should an animation hold up a data request, they are mutually exclusive, but the intro animation depends on them both! please advise, thanks!
Assigning Multiple Events To One Function
Hey, I want to know if it is possible to assign multiple events to one function without making a separate event function for each event.
For example I want two movieclips to invoke the same function when they've
clicked. Right now to achieve this I have the following:-
ActionScript Code:
var mc1 :MovieClip = this.bar1;
var mc2 :MovieClip = this.bar2;
/*******
*
* @ Do the Events for the First Bar
*
***/
mc1.onPress = function(){
Bars_onPress(this);
};
mc1.onRelease = function(){
Bars_onRelease(this);
};
mc1.onReleaseOutside = function(){
Bar_onReleae(this);
};
/*******
*
* @ Do the Events for the Second Bar
*
***/
mc2.onPress = function(){
Bars_onPress(this);
};
mc2.onRelease = function(){
Bars_onRelease(this);
};
mc2.onReleaseOutside = function(){
Bar_onReleae(this);
};
What i want to do is assign multiple events to one function:-
ActionScript Code:
var mc1 :MovieClip = this.bar1;
var mc2 :MovieClip = this.bar2;
/*******
*
* @ Assign the function to both mc1 !!AND!! mc2
*
***/
mc1.onPress,
mc2.onPress = function(){
Bars_onPress(this);
};
/*******
*
* @ Here I want to Assign to function to BOTH mc1 !!AND!! mc2 !!AND!!
* to two of their events (onRelease AND onReleaseOutside)
*
***/
mc1.onRelease,
mc1.onReleaseOutside,
mc2.onRelease,
m2.onReleaseOutside = function(){
Bars_onRelease(this);
};
The funny thing is when I do this, it doesn't throw a syntax error. However when I run it, it only assigns the function to the last event (ie for onPress "mc2.onPress" is the only event, and for onRelease "m2.onReleaseOutside" is the only event).
I know you can use it this way (but I'm trying to cut down on the amount of functions, and those same functions are invoked in different situations outside of the onPresss, onRelease and onReleaseOutside events. So this object inside of those functions will conflict in the other situations the function is being used
ActionScript Code:
m1.onPress = Bars_onPress;
m1.onRelease = Bars_onRelease;
m1.onReleaseOutside = Bars_onRelease;
m2.onPress = Bars_onPress;
m2.onRelease = Bars_onRelease;
m2.onReleaseOutside = Bars_onRelease;
Movie Clip Events In A Function?
Can I put movie clip events like onRollOut () {}; in a function and then just run the function on a movie clip?
I'm thinking something like this:
Code:
function onClip() {
onRollOut(){ gotoAndStop(3) }
}
//Then call this on the movie clip:
onclip();
Please let me know if this would work.
Thanks.
Overriding The Clone Function In Events
So, if i want to dispatch the same event again but with another parameters why cant i override the clone function to put those parameters in it?I mean,something like
pubic override function clone(par1, par2){
semms that flash dont like it, and also since the clone function itself creates another instance of my custom event i cant change the parameters in the old one and expect them to be in the new one...
So, whenever i want to want to dispatch an event with another public variables will i have always to create a new instance of my event?
Function Runs When 3 Events Are Dispatched
Hello everybody, I was wondering if it's possible with as3 to run a function when 3 processes are completed. What I mean is that if I have this 3 Objects:
Code:
1. var myloader:Loader = new Loader();
2. var myurlloader:URLLoader = new URLLoader();
3. var myanimator:Animator = new Animato
r();
I have a function named:
Code:
function next_function():void {
trace("it works");
}
I have 3 listeners.
Code:
myloader.contentLoaderInfo.addEventListener(Event.COMPLETE, function1);
myurlloader.addEventListener(Event.COMPLETE, function2);
myanimator.addEventListener(MotionEvent.MOTION_END, function3);
Is there a way that the function just runs once the 3 of the listeners have dispatched the COMPLETE and END events?
Well that's my question, I'm simply trying to learn some AS3 and I was trying to do this but I haven't figured how, any help would be appreciated...
Dispatching An Event From Inside Another Events Listener Function
Hello,
Is it possible to dispatch an event from inside another events listener function and have it bubble up to the correct location or even bubble at all?
I have a feeling that since the dispatch is occuring from within another events listener function that it is locked somehow and cannot communicate outside of itself unless I create a custom event.
I ask because I am trying to do something like this:
ActionScript Code:
// test the HourGlassDial
oHourGlassDial = new HourGlassDial();
oHourGlassDial.addEventListener(HourGlass.HOUR_GLASS_ROTATED, onHourGlassRotated);
////////////////
public function onHourGlassRotated(e:Event):void
{
trace("onHourGlassRotated");
// Increment the oHourGlass by 1 frame
if (oHourGlass.currentFrame < oHourGlass.totalFrames) {oHourGlass.gotoAndStop(oHourGlass.currentFrame+1);}
}
ActionScript Code:
////////////////
public function onTimeIntervalComplete(e:HourGlassRotationIntervalEvent):void
{
trace("onTimeIntervalComplete: dispatching HOUR_GLASS_ROTATED event");
trace ("currentCount =" + e._timerEvent.target.currentCount);
trace ("repeatCount =" + e._timerEvent.target.repeatCount);
// dispatch the TIME_EXPIRED event to all subscribers
dispatchEvent(new Event(HourGlass.HOUR_GLASS_ROTATED));
}
////////////////
But when the onTimeIntervalComplete listener function runs I can see the traces for it, but when its suppose to dispatch the HOUR_GLASS_ROTATED event I never see the traces from the onHourGlassRotated listener function.
Any suggestions?
many thanks in advance,
frank grimes
Programatically Create Buttons, Handle Click Events With 1 Function
Hey everyone, this is my first time posting here and i'm happy to be part of the community. My question is this: I am trying to make a number of movie clips that will work as buttons, all of which will look identical. I want to create them in a programmatic way(say, with a while statement), and then instead of checking for "cases" in the handler, which seems sloppy, I'd like to call one function with parameters when a button is clicked. these parameters would contain the instructions for what the function will do, for example in actionscript 2 I could write:
somebutton.onpress = function() {
clickhandler(param1, param2, param3)
}
Then have the clickhandler function take those arguments and do specific things with them. Is there a way to call a function and pass it arguments like this? Thanks ahead of time!
Here is snippets from my code (this isn't the full code; didn't want to make everyone go through the whole program to get my point)
ActionScript Code:
var buttonStateT1:String = "none";
var arraycount1:int = 0;
var tier1Array:Array = new Array(T1B1_MC, T1B2_MC, T1B3_MC);
T1B1_MC.buttonMode = true;
T1B1_MC.addEventListener(MouseEvent.CLICK, clickHandler)
T1B2_MC.buttonMode = true;
T1B2_MC.addEventListener(MouseEvent.CLICK, clickHandler)
T1B3_MC.buttonMode = true;
T1B3_MC.addEventListener(MouseEvent.CLICK, clickHandler)
function clickHandler(event:MouseEvent):void {
trace(event.currentTarget.name);
switch (event.currentTarget.name) {
case "T1B1_MC" :
if(buttonStateT1 == "B1"){
tier1FuncReverse(T1B1_MC);
break;
}
if(buttonStateT1 == "none"){
buttonStateT1 = "B1";
tier1Func(T1B1_MC);
trace("yeah1");
break;
}
else{
break;
}
case "T1B2_MC" :
if(buttonStateT1 == "B2"){
tier1FuncReverse(T1B2_MC);
break;
}
if(buttonStateT1 == "none"){
buttonStateT1 = "B2";
tier1Func(T1B2_MC);
trace("yeah2");
break;
}
else{
break;
}
}
}
function tier1Func(bname:Object){
trace("called t1func");
for(var i:int=0;i<3;i++){
if(bname == tier1Array[i]){
trace(tier1Array[i]);
}
else{
trace(tier1Array[i]);
tier1Array[i].y = tier1Array[i].y + 8;
}
}
}
function tier1FuncReverse(bname:Object){
trace("called t1func");
for(var i:int=0;i<3;i++){
if(bname == tier1Array[i]){
trace(tier1Array[i]);
buttonStateT1 = "none";
}
else{
trace(tier1Array[i]);
tier1Array[i].y = tier1Array[i].y - 8;
buttonStateT1 = "none";
}
}
}
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.
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.
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
Function In A Function In A Function, A Scope Problem
Is this basic or what.. I have a nested functions, and I'm having a hell of a time getting all my variable through.
ActionScript Code:
var canyouseemee;
public function move()
{
for(var i:Number = 0; i < blah; i++)
{
zing, and then zang
if (zing==0)
{
guts
}
if (zang ==0)
{
something else
}
}
}
Now, I had always thought that since var canyouseemee is declared at the topmost layer, that I'd be able to see it from anywhere below it. Well, it turns out that I can only see it from within the move()function, and not anything below it. is this normal? I thought you couldn't see a local variable of a lower (deeper) function, but could see higher (shallower) variables...
Call A Function In A Duplicated Movie Clip Form Another Function : (
i have a movie clip on my root name "pl".
on command, it duplicates with instance name as "y0","y1", etc.
here is the method :
function callPL(transmit,receive,addy,level) {
var newName = "y"+_root.x;
duplicateMovieClip("_root.pl",newName,101);
_root[newName]._x = 400;
_root[newName]._y = 400;
_root.[newName].start(transmit,receive,addy,level); //look here
}
there i attempt to call a function of the newly duplicated clip call "start()".
Start() function is written on the first frame of the movieclip like this :
function start(a,b,address,level) {
a.sendAndLoad(address,b,"Post");
this.path = b;
b.onLoad=function(success) {
gotoAndPlay("start");
}
}
however it seems like the function callPL() could not invoke function start() of the new movieClip.I have no idea how is it so.
Even when i trigger it with a onLoad handler it still doesnt work
pls shed some light.
Calling Constructor In Condition: A Function Call On A Non-function Was Attempted.
Hi guys,
Please help me somebody with this cos I have really no idea. I have made a simply condition calling a constructor of a class. Today I had to add an "else if", what caused the compilator to show me "A function call on a non-function was attempted."...
ActionScript Code:
function loadIt() { if (var1 == "1") { var a:SomeClass = new SomeClass(true); } else if(var2 == "1"){ var a:SomeClass = new SomeClass(false); //<- if this is not here, everything works fine } else { var b:SomeOtherClass = new SomeOtherClass(); b.init(); }}
Any ideas? Thanks for any help!
Poco
Filling Function Arguments With Array Items, Function.call()
HI!
I have this code but I cannot work out how to fill in function parameters based on an array and it's length, see line 7
ActionScript Code:
import com.robertpenner.easing.Cubic;MovieClip.prototype.framesTimeout = function(func:Function, frames:Number, args:Array) { var t:Number = 0; var mc:MovieClip = this.createEmptyMovieClip(String(new Date().getTime()), this.getNextHighestDepth()); mc.onEnterFrame = function() { if (t == frames) { func.call(this._parent,args); delete this.onEnterFrame; this.removeMovieClip(); } else { t++; } };};MovieClip.prototype.movex = function(x:Number, frames:Number) { trace(x+" "+frames) delete this.movex.onEnterFrame; this.movex.removeMovieClip(); if (!frames) { frames = 20; } var t:Number = 0; var sx:Number = this._x; var ax:Number = x-this._x; var mc:MovieClip = this.createEmptyMovieClip("movex", this.getNextHighestDepth()); mc.onEnterFrame = function() { if (t == frames) { delete this.onEnterFrame; this.removeMovieClip(); } else { t++; this._parent._x = Cubic.easeOut(t, sx, ax, frames); } };};MovieClip.prototype.otherfunction = function(param1, param2, param3, param4){ trace(param1+" "+param2+" "+param3+" "+param4)}mc.framesTimeout(movex, 50, [100, 50]) mc.framesTimeout(otherfunction, 200, ["asd", 1, 2, 55])
Is it possible to call a function and fill in the parameters based on an array and it's lenth?
My Function Isn't Functioning/Actionscript To Call A Function Flash MX 2004
Hello,
Well in theory I know how to create a function but for some reason I am unable to call it.
Can someone take a look at it and tell me what went wrong. Basically when I go to "a certain page" I want to click on a button and have it go to another page known as "pics" it then will load a jpeg there known as jpeg loader. Now I know it works properly without a functin, but because I am lazy I do not want to write more code than I have to, there are like 300 differnt jpegs I have to load. Thus I need to create a function.
here is my AS
ActionScript Code:
//this is on frame one of my root timeline
//I am trying to call the function "display" on release of my button
omnihotelButton.onRelease = display ("J010 Omni Hotel.jpg");
//this is my function that I set up it is also on my root, but on a different frame
//this function is named display and it goes to the "pics" page and stops
where it then loads a jpeg which is et up as my variable.
//the xscale and the yscale are just setting up my size of the jpeg.
function display(jpeg){
_root.gotoAndStop("pics");
jpegLoad_mc.loadMovie(jpeg);
jpegLoad_mc._xscale=90;
jpegLoad_mc._yscale=90;
}
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!
|