EventHandler Problem
I have created a function. In it I am listening to a change in 2 textFields. I get the values of them. I show their product in third textField. All this is working fine. But I want to sum all the products I get. I can't figure put how to do this. First I was thinking of array and tried to push the value, then I tried join, but nothing work . This is my code: Code: private function onChange(event:Event):void { _num1 = Number(num1.text); _num2 = Number(num2.text); _proizvedenie = _num1 * _num2; proizvedenie.text = String(_proizvedenie); } Please someone help. I want to sum all the _proizvedenie vars I'll get. 10x in advance. I'll be very grateful if someone helps
KirupaForum > Flash > ActionScript 3.0
Posted on: 07-24-2008, 03:53 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
EventHandler?
Hey everyone,
I'm working on a project and got stuck so I was wondering if anyone can make a suggestion to help me out.
My problem (I think) is very simple. I have a button that when I rollover it tells an mc to perform some small animation. What I want to do is when the first mc finishes playing its animation, for a second movie clip to begin.
In the example my button (onRollOver) will make a menu slide from the left. When the menu is completely exposed I want the menu items to fade in.
Would I use an eventHandler for this?
All my animations are in code (no Tweening)
Thanks
Eventhandler
I would like to know if its possible to dispatch an Event (dispatchEvent (..)) on a movie and listern with another movie which does not exist on the same movie clip as the dispatcher.
NO EventHandler
I am trying to figure out a way to get result data from a
url request without using event handlers. any ideas
[CS3] BlurFilter/EventHandler
Hi guys, I am having some problem figuring out how this works in AS3,
I have a movie clip called mc1, which blurs on enterFrame, how can I revers this onRollover, using event handler.
what i want is when the mouse rolls over the clip, it should be normal and when the mouse is out returns to blur,
Pls can some one give me alead ?
thanks
my code is:
Quote:
import gs.TweenLite;
import flash.events.MouseEvent;
import gs.TweenMax;
import gs.easing.*
import flash.display.*;
import flash.events.*;
function enterFrame_handler(e:Event):void {
TweenMax.to(mc1, 1, {blurFilter:{blurX:15, blurY:15}});
}
function onRollover(event:MouseEvent):void {
TweenMax.to(mc1, 1, {blurFilter:{blurX:0, blurY:0}});
}
function onRollout(event:MouseEvent):void {
TweenMax.to(mc1, 1, {blurFilter:{blurX:15, blurY:15}});
}
function onClick(event:MouseEvent):void {
TweenMax.to(mc1, 1, {blurFilter:{blurX:0, blurY:0}});
}
mc1.addEventListener(MouseEvent.ROLL_OUT, onRollout);
mc1.addEventListener(MouseEvent.ROLL_OVER,onRollov er);
mc1.addEventListener(Event.ENTER_FRAME, enterFrame_handler);
[CS4] Help With EventHandler, Mouseover, Etc
Hello,
Can someone please help me with this code, it is throwing an error?
aero = small MC located on stage (image of .aero logo)
textbox = dynamic textbox also located on stage, has no text at start
Code:
aero.addEventHandler ('mouseOver', callback_handler) = function() {
textbox.text = "This is the .aero extension";
}
aero.addEventHandler ('mouseOut', callback_handler) = function() {
textbox.text = " ";
}
The error I'm getting is saying Line 1:
1105: Target of assignment must be a reference value.
Problem With Eventhandler
Hello,
I'm a newbie with Actionscript 3, but try my best to learn it. So far i got hardly everything going, but now I got stuck with an eventhandler problem. My main timeline has only 1 frame which contains several layers which themselves contain movieclips ( and even movieclips in movieclips), background etc.
So in one layer i got a movie clip, which again contains a movieclip, with buttons inside (kind of dynamic menu appears on demand), so construction is:
root.mc.mc.button
therefore I set an eventhandler which gets the mouseclicks. The buttons work fine the first time the ymovie with the buttons appears. Then another function in the animation "hides" the mc with buttons in it behind a mask. Once the mc with the buttons on it appears again (moves out of the mask) the buttons wont react to mouseclicks any more (but they still correspond to the buttons-states like over, clicked etc.)
It feels like the eventhandler isn't reacting anymore. Anybody any idea? How can I find out if the eventhandler still exists? Any help is welcome
All the code is in the main timeline frame 1.
thanks in advance
Alex
Array Eventhandler ?
is it possible to do something like this?
var items:Array;
items = new Array();
var arrChangeListener:Object = new Object();
arrChangeListener.onChanged = function() {
trace("updated item Arr");
};
items.addListener(arrChangeListener);
What Im trying to do is to execute some code whenever the data in the array changes, but I can't get it to work. Does the array class even have this functionality ?
-Cheerios!
Tween In EventHandler Of Class?
in my class constructor, i add a eventListener, and in that eventlistener i add a tween:
myTween = new Tween(this, "tweenNum", Elastic.easeOut, 0, 1, 60);
like that.. however that doesn't seem to work, the tweenNum is a Number-variable of the class:
private var tweenNum:Number=0;
the problems seems to be the "this" keyword which i pass as the first argument, obj, of the Tween.
if i change the var to this:
private var tweenNum:Object={a:0};
and the tween to this
myTween = new Tween(tweenNum, "a", Elastic.easeOut, 0, 1, 60);
it works fine.
but that looks like a ugly workaround to me...
how would you better go on about doing that?
thanks
TextField OnClick EventHandler
Right guys, sorry, Friday afternoon, and my brain has packed up! I'm just trying to get a text field to recognise that it's been clicked!!! Some-one please put me out of my misery! I'm no newbie, just been a long week and now my head decided to go on strike!
Trigger A Function From MC EventHandler
hi ya all.
i have made a dynamic text and jpg loader with animation transition.
i used a function for fadeIn and a function for fadeOut.
but i had to use a different function for each item.
i want to try and sumplify the code so i could fade each item with just two functions (fadeIn() & fadeOut();)
so naturaly i used properties. the problem is that the properties dont seem to work from within the eventHandler.
you can download the file and check out the code from:
http://planet.nana.co.il/examples/
thanks
nivosh
nivosh
nivosh@hotmail.com
How Do I Transfer Parameter Into EventHandler?
hi
I have the following function:
function name(var1,var2){
... commands using var1,var2
}
and would like to use this function as eventHandler:
mc.onEnterFrame = name;
or maybe better to understand:
btn1.onRelease = name;
btn2.onRelease = name;
where var1,var2, depend on the button.
What do I do with var1,var2, or more specific, how do I assign theses two?
(I know how I could to it via a local variable using this, or even using a global var, but for the sake of good and fast code, I would like to use function parameters.)
Any ideas?
Do I miss a point?
thanks a lot
marcel
Problem CreateEmptyMovieClip And EventHandler
why when i create a movieclip with createEmptyMovieClip then load an external swf into it and change its properties (all this work)
but when i try to assign an event handler like onPress it don't work this is an exemple :
stop();
mymcl = new MovieClipLoader();
mylistener = new Object();
mylistener.onLoadInit = function(targetmc){
trace ("hello");
targetmc.onPress=function() {
trace ("what");
getURL("1.htm","_blank");
}
}
_root.createEmptyMovieClip("x1",5000);
mymcl.loadClip("1.swf","x1");
mymcl.addListener(mylistener);
i see hello in the output but the onPress event don't work
now its the 5th days spent on this problem
i found a solution based on getBytesLoaded and getBytesTotal with the onEnterFrame event but this solution don't fit to my project i choose listener
any help could be appreciate
Changing .text Property From Eventhandler
Code:
var FacilityPassListener = new Object();
LName.addEventListener("focusIn", LNameListener);
LNameListener.handleEvent = function(eventObj) {
trace("listener is LNameListener"); //as expected
if (eventObj.name == "focusIn"){
login_mc.myText._y = row2; //no change
login_mc.myText.text = "enter name."; //no change
}
I'm able to fire the correct event via the inputtext control (LName) but I can't get the code inside the handler to control the text field.
I've reviewed notes on the delegate class but that doesn't appear to apply to this situation. Or does it?
Receive EventHandler When Flash Loads..
I have little problem in my flash application.. It doesn't receive keyboard event, when the page loads the user need to press spacebar to start the application.. But it seems my flash doesn't get the onKeyDown event.. I need to click first the application so that it can get the event. Is there any solution for this problem or work around?
Custom Eventhandler Giving More Headaches
Hi all
I'm having huge difficulties getting my custom eventhandler to work. For some reason my eventhandler doesn't get triggered. My eventhandler should get triggered, when my form is submitted. Here is what I have got so far:
Custom event class called submitEvent.as:
Code:
package
{
import flash.events.Event;
public class submitEvent extends Event
{
public static const ON_FORM_SUBMIT:String = "onFormSubmit";
public function submitEvent(type:String)
{
super(type);
}
public override function clone():Event
{
return new submitEvent(type);
}
}
}
When form is submitted, dispatch event from submitForm class file:
Code:
dispatchEvent(new submitEvent(submitEvent.ON_FORM_SUBMIT));
Listener set up in document class file:
Code:
var emailSubmitform:submitForm = new submitForm();
emailSubmitform.addEventListener(submitEvent.ON_FORM_SUBMIT, onFormSubmit);
function onFormSubmit(e:submitEvent):void
{
trace("FORM IS SUBMITTED");
}
addChild(emailSubmitform);
Code Won't Continue After Removing Eventhandler
Hi there,
i've got a function containg other functions and listeners...
I want to get back the amount of collected items in this game...
when everthing is done, i set the exit bool to true and the listeners are deleted, but, the program stops there. after the trace "key listeners removed" comes once again the trace "sdkfjkdsfj" and then the program should give back the collectedAmount... but it doesn't...
please help me...
ActionScript Code:
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.*;
import flash.net.URLRequest;
trace(startGame());
function startGame():int{
...
...
...
function moveNerd(event:KeyboardEvent):void{
var speed:int = 20;
if(event.keyCode == 38){
trace("nach oben gedrückt")
//circle.y -= 5;
}
else if(event.keyCode == 40){
trace("nach unten gedrückt")
//circle.y += 5;
}
else if(event.keyCode == 37){
trace("nach links gedrückt");
if(!(nerd.x <= 35))nerd.x -= speed;
}
else if
(event.keyCode == 39){
trace("nach rechts gedrückt");
if((nerd.x < 500))nerd.x += speed;
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, moveNerd);
//This loop creates 40 particles that are positioned randomly on the stage.
for (var i=....
....
...
}
trace("done!");
function enterFrameHandler (e:Event):void {
//Loop through the particles
var exit:Boolean = false;
for (var i = 0; i < particlesArray.length; i++) {
var particle = particlesArray[i];
var Badparticle = BadparticlesArray[i];
particle.y += particle.speedY;
particle.x += particle.speedX;
Badparticle.y += Badparticle.speedY;
Badparticle.x += Badparticle.speedX;
if(nerd.hitTestObject(particle)){
particle.y = 0;
particle.x = Math.random() * stage.stageWidth;
++collectedAmount;
}
else if(nerd.hitTestObject(Badparticle)){
Badparticle.y = 0;
Badparticle.x = Math.random() * stage.stageWidth;
if(collectedAmount > 0)
--collectedAmount;
}
AmountField.text = ("Anzahl: " + collectedAmount);
//If the particle is below the bottom, position it back to the top
if (particle.y > stage.stageHeight) {
particle.y = 0;
particle.x = Math.random() * stage.stageWidth;
}
if (Badparticle.y > stage.stageHeight) {
Badparticle.y = 0;
Badparticle.x = Math.random() * stage.stageWidth;
}
if(TimerField.text == "Time's up!"){
exit = true;
//break;
}
}
if(exit == true){
removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
trace("enter-listener entfernt");
stage.removeEventListener(KeyboardEvent.KEY_DOWN, moveNerd);
trace("key listener removed");
}
trace("sdkfjkdsfj");
}
addEventListener (Event.ENTER_FRAME, enterFrameHandler);
return collectedAmount;
}
Text Within Movieclip In Eventhandler Function
Hi: I'm trying to access the TextField that is within my movieclip that has an EventHandler attached to it. And having no luck. Any thought?
ActionScript Code:
function loadServices():void {
for (var g:uint=0; g<3; g++)
{
for (var k:uint = 0; k< 5; k++) // loop through to add create background pattern
{
var serviceClip:MovieClip = new MovieClip();
var serviceTxt:TextField = new TextField;
serviceTxt.textColor = 0xFFFFFF;
serviceTxt.x = serviceClip.x + 10;
serviceTxt.width = 70;
serviceTxt.wordWrap = true;
serviceClip.graphics.beginFill(0x96cad4);
serviceClip.graphics.drawRoundRect(0, 0, 80, 80, 18, 18);
serviceClip.graphics.endFill();
serviceTxt = "this is the text" + k;
serviceTxtArray[k] = serviceTxt;
serviceClip.y = serviceClip.y + (k * 83) ;
serviceClip.x = serviceClip.x + (g * 83);
serviceClip.addChild(serviceTxt);
serviceClip.buttonMode = true; //this line causes the hand cursor to appear
serviceTxt.mouseEnabled = false; //without this line, the textfield will interfere with clicks
serviceClip.name = "button" + k;
serviceContainer.addChild (serviceClip);
serviceClip.addEventListener(MouseEvent.MOUSE_OVER,mouseOn);
serviceClip.addEventListener(MouseEvent.MOUSE_OUT, mouseOff);
}
}
}
function mouseOn(event:MouseEvent):void {
//????? event.target.child.text.textColor = ????? }
Receive EventHandler When Flash Loads..
I have little problem in my flash application.. It doesn't receive keyboard event, when the page loads the user need to press spacebar to start my application.. But it seems my flash doesn't get the onKeyDown event.. I need to click first the application so that it can get the event. Is there any solution for this problem or work around?
How Do I Handle Callbacks/eventHandler Scope In AS 2.0 Classes?
I am trying to integrate an XML loading script into my FLA. I got the script from a book (I'm learning this) and it worked fine when in a timeline frame (loaded all perfectly well), but when I put it into an AS 2.0 class (which I'd been using with hardcoded data for testing) all fails miserably. I'm trying to get the loaded XML data processed with another class private function when the onLoad event comes from loading the XML, but this second function never gets called. All just fails silently. PLUS I'm trying to store the loaded data into two arrays which are class properties so that I can access the data later. They are not accessible. If this seems muddled it's only because I've been banging my head against this for 2 hours. I've read Moock, and then I went to Macromedia's online help -- and you will see in my code that I tried to set up an "owner" variable to clarify scope. It didn't. Basically: how does one handle scope of other class functions AND class properties from within an event handler in the class? As a very important bonus question: is there a way to set up eventListeners and callback functions between classes, or is this verboten?
Please help if you can -- I know it's obvious to you, and soon perhaps to me --
Thanks -- Robert
(Code follows)
Code:
class DataRetriever {
private var id:ImageData;
private var thePics:Array;
private var theThumbs:Array;
private var url:String;
private var currentNumber:Number = 0;
private var xmlLoaded:Boolean;
public function DataRetriever(url:String) {
this.url = url;
theThumbs = new Array();
thePics = new Array();
xmlLoaded = false;
}
public function xmlIsLoaded():Boolean {
return xmlLoaded;
}
public function getNextData(theID:ImageData):Boolean {
if (currentNumber>=thePics.length) {
// return error if we're going too far
return false;
}
theID.mainUrl = thePics[currentNumber];
theID.thumbUrl = theThumbs[currentNumber];
theID.dataNum = currentNumber++;
return true;
}
private function getXML():Void {
// Create new XML Object and set ignoreWhite true
var photos_xml:XML;
photos_xml = new XML();
photos_xml.ignoreWhite = true;
// Setup load handler which just invokes another function
// which will do the parsing of our XML
var owner:DataRetriever = this;
photos_xml.onLoad = function(success) {
if (success) {
owner.processPhotos(photos_xml);
}
};
// Load up the XML file into Flash
photos_xml.load('photos.xml');
// This is the function that will be called when
// our XML document is loaded succesfully
}
private function processPhotos(photos_xml:XML):Void {
xmlLoaded = true;
var photo:Object;
photo = new Object();
for (var n = 0; n<photos_xml.firstChild.childNodes.length; n++) {
var noddy:XMLNode = photos_xml.firstChild.childNodes[n];
for (var m = 0; m<photos_xml.firstChild.childNodes[n].childNodes.length; m++) {
switch (m) {
case 0 :
theThumbs[n] = photos_xml.firstChild.childNodes[n].childNodes[m].firstChild.nodeValue;
break;
case 1 :
thePics[n] = photos_xml.firstChild.childNodes[n].childNodes[m].firstChild.nodeValue;
break;
}
}
}
}
}
Problem Moving EventHandler From Frame To AS Package
Hi - I'm a newbie to Actionscript and stuck on something simple.
I had a .fla with this mouse event handler attached to a button (instance name btnIntroduction) with AS attached to the frame... The handler & function worked fine but when the AS is moved into a external class package file and using FlashDevelop for coding. Now the event handlers won't work because they won't attach. I get the error message:
1120: Access of undefined property btnIntroduction.
What do I need to do in my external .AS file to make it attach the button eventHandler?
Any help appreciated -- Thank you
////// AS that worked when attached within .FLA inside of a frame:
function goIntroduction (e:MouseEvent):void {
gotoAndPlay("Introduction");
}
btnIntroduction.addEventListener(MouseEvent.CLICK, goIntroduction);
//////// AS that fails - when inserted into external package.
// Filename: Main.as which is the same as the Document class in .FLA
package
{
import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.text.TextField;
public class Main extends MovieClip
{
public function Main()
{
btnIntroduction.addEventListener(MouseEvent.CLICK, goIntroduction);
}
btnIntroduction.addEventListener(MouseEvent.CLICK, goIntroduction);
} // End of class Main
} // End of package
Array Stuff Lost After Finish Loading A EventHandler.
array stuff lost after finish loading a eventHandler.
When my EventHandler for the Event.COMPLETE of xml URLLoader()
finish running this:
publicfunction imageLoad(u:String):void{
imgLoader = new Loader();
imgRequest = new URLRequest(u);
imgLoader.load(imgRequest);
// imgLoader.content as MovieClip;
trace(buffer.length);
buffer.push(imgLoader);
}
which load images into array, buffer.
When I get back to constructor, there's nothing in the buffer array.
WHy?
thank you
I Made An EventHandler Frame Rate Measurement Code
Could you debug my METHOD 2?? (please see Line#11 (it's Line#20 in the attachment) or the statement
if(x>framerate) )
It has two methods of knowing the frame rate..
Method1: measures only ONE ITERATION of the whole onEnterFrame method regardless of frame rate because it EXPLICITLY multiplies it with the framerate variable (assuming you set 12 on your movie).
Method 2: I'm not sure if line#11 (line#20 in fla) should be
if(x ==framerate)
but if i did that, it seems that the estimated frame rate is about 30 ms shorter than the expected 1000 ms. But if I use the
"<" operator, it's closer to method 1.
HELP..
PHP Code:
var x=1;
var framerate = 12;
function EventHandlerRate(){
var currenttime = getTimer();
if(x==1){
starttime=currenttime;
}
timeElapse = currenttime - this.prevTime;
trace("METHOD1: "+timeElapse*framerate+" milliseconds");
this.prevTime=currenttime;
if(x>framerate){
txt1 = "START : ";
txt2 = "END : ";
txt3 = "TIMEELAPSE is ";
endtime = getTimer();
trace("
"
+"==============================
"
+"METHOD 2:
"
+"==============================
"
+txt1 + starttime + "
"
+ txt2 + endtime + "
"
+ txt3 + (endtime - starttime)
+"
");
x=0;
}
++x;
}
this.onEnterFrame = EventHandlerRate;
I Made An EventHandler Frame Rate Measurement Code
Could you debug my METHOD 2?? (please see Line#11 (it's Line#20 in the attachment) or the statement
if(x>framerate) )
It has two methods of knowing the frame rate..
Method1: measures only ONE ITERATION of the whole onEnterFrame method regardless of frame rate because it EXPLICITLY multiplies it with the framerate variable (assuming you set 12 on your movie).
Method 2: I'm not sure if line#11 (line#20 in fla) should be
if(x ==framerate)
but if i did that, it seems that the estimated frame rate is about 30 ms shorter than the expected 1000 ms. But if I use the
"<" operator, it's closer to method 1.
HELP..
PHP Code:
var x=1;
var framerate = 12;
function EventHandlerRate(){
var currenttime = getTimer();
if(x==1){
starttime=currenttime;
}
timeElapse = currenttime - this.prevTime;
trace("METHOD1: "+timeElapse*framerate+" milliseconds");
this.prevTime=currenttime;
if(x>framerate){
txt1 = "START : ";
txt2 = "END : ";
txt3 = "TIMEELAPSE is ";
endtime = getTimer();
trace("
"
+"==============================
"
+"METHOD 2:
"
+"==============================
"
+txt1 + starttime + "
"
+ txt2 + endtime + "
"
+ txt3 + (endtime - starttime)
+"
");
x=0;
}
++x;
}
this.onEnterFrame = EventHandlerRate;
Problem With EventHandler For Object Instantiated Inside Another Objec
Hi there,
In my application I have a container object (ContainerSquares) that has a number of smaller objects (Square). I create an instance of the container class on the main timeline, and create the instances of the squares inside of the container class. The Square object is a movieClip in the library that is linked to the Square class.
I can create these movieclips fine, but when I try to code an onRelease for them, I can't seem to reference any functions outside of the onRelease function. If I put a trace directly inside of the onRelease I can see it, but if I put a function inside the container class with a trace, and call that from the onRelease function, I can't see that (I've tried referencing it with every syntax I could think of (_root.container.function, this.cParent.function [cParent is a var in Square, it references the parent container]), I've also tried putting the function to call in the Square class, and the main timeline, and I can't seem to call any other function belonging to any of them (main movie, Container, or Square) inside of this onRelease.
The other weird thing is that I can perform the actions directly inside of the onRelease handler. I can check what frame that instance of a mcSquare is on, and tell it to gotoAndPlay("something")... but I have a few of them, and it seems ridiculous to code the same thing directly into each onRelease.
This works:
CODEthis.mcSquare1.onRelease = function(){
trace("in onRelease");
if(this._currentframe > 19){
this.gotoAndPlay("next");
}else if (this._currentframe > 9){
this.gotoAndPlay("big");
} else if(this._currentframe > 0){
this.gotoAndPlay("next");
}
}
|