Get Name Of Function / Event Handler
Does anyone know if there is a way to get the name of the function that my code is running inside?
Code:
_btn.onPress = function () {
trace(something);
}
this would then output "onPress" or something like it... hope you all understand what i'm searching for.
Thanks!
KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 10-19-2005, 04:15 PM
View Complete Forum Thread with Replies
Sponsored Links:
Dynamic Function On Event Handler
Hi, i am creating a simple menu and all of my data is stored in a struct that was pulled over from a text file using loadVars.
This is supposed to populate the menu
Code:
function populateMenu(articleStruct)
{
var i = 1;
//while(i < articleStruct.num)
while(i < 8)
{
_root.attachMovie("btnArticle","btnArticle"+i,i);
_root["btnArticle"+i].menuText.text = articleStruct["artitle"+i];
_root["btnArticle"+i]._x = 65;
_root["btnArticle"+i]._y = 100+i*20;
var curDate = articleStruct["date"+i];
var curTitle = articleStruct["artitle"+i];
var curArticle = articleStruct["article"+i];
_root["btnArticle"+i].onRollOver = function()
{
_root.articleTextVar = curArticle;
_root.titleTextVar = curTitle;
_root.dateTextVar = curDate;
trace("I: " + i);
}
i++;
}
}
It creates the buttons fine, but when it comes to the functions attached i am stuck. It always uses the same article no matter what button i rollover. So i added it to trace the i, and it is revealing the last i set in the while loop. Is there really only one instance of this function and it keeps writing itself over?
Thanks
View Replies !
View Related
Flexible Event Handler Function
Is there a way to create a function that handle events (especially MouseEvents) and still call this function as a plain one without passing any arguments? All this time, I just create an extra function that handles the mouseEvent and call the needed function inside it.
Example:
function handler(e:MouseEvent):void{
realFunction();
}
function realFunction():void{
// I want this function to work as a handler and at the same time a plain function
}
Just thought that maybe there's a better way of doing it.
Thanks in advance.
View Replies !
View Related
Function Only Works At Runtime, Not Event Handler
Hi All;
anyone can help me figure out why this only works when my function buttonCount(); is called a runtime? When I call it via the event hander, it doesn't work.
I'm trying to make a dynamic set of sub-menu buttons, determined by the number is var sCount.
Thanks in advance -- code below, .fla attached.
J
-------
var sCount:Number = 4
var dButton:MovieClip;
function sButton() {
for (i = 1; i <= sCount; i++) {
_root.attachMovie("slide", "slide" + i, i);
dButton = _root["slide" + i];
dButton._x = 200 + (27 * i);
dButton._y = 400;
}
}
// --- this works only when the function called at runtime, not via the button - why??? //
sButton();
btn.onRelease = function () {
sCount = 4;
sButton();
}
slide1.onMouseDown = function() {
if (this.hitTest(_root._xmouse, _root._ymouse)) {
trace ("slide 1");
updateAfterEvent();
}
}
slide2.onMouseDown = function() {
if (this.hitTest(_root._xmouse, _root._ymouse)) {
trace ("slide 2");
updateAfterEvent();
}
}
slide3.onMouseDown = function() {
if (this.hitTest(_root._xmouse, _root._ymouse)) {
trace ("slide 3");
updateAfterEvent();
}
}
slide4.onMouseDown = function() {
if (this.hitTest(_root._xmouse, _root._ymouse)) {
trace ("slide 4");
updateAfterEvent();
}
}
View Replies !
View Related
Event Handler Function Returns Values - HOW To Get Them?
Hello I probably am not understanding how Events work....well I have function in a class that has this line of code:
ActionScript Code:
this.addEventListener("dataRetrieved", handleHierSelectData);
"dataTrieved" is a custom event that dispatches an event with a variable set to "true".
In another section of my code I have the event dispatch:
ActionScript Code:
public function onGetRecordsResult(result:Array = null):void
{
// convert the result array into an array
phpData = new ArrayCollection(result);
// instantiate new custom event, set the appropriate data to send back and
// dispatch event to parent app or component
var e:DataRetrievedEvent = new DataRetrievedEvent();
e.dataRetrieved = true;
dispatchEvent(e);
}
From the addevent listener line I call "handleHierSelectData"
ActionScript Code:
public function handleHierSelectData():Canvas
{
newProgressBar.indeterminate = false;
newProgressBar.visible = false;
newHierSelect = new ThreeLevelHierSelect('processData', listLabels, null, phpData);
//myCanvas.addChild(newHierSelect.generateHierSelect());
return newHierSelect.generateHierSelect();
}
See, handleHierSelectData creates a new component that I need to send to my main application so I am wonder WHERE, AND HOW I can get the returned component from this.addEventListener("dataRetrieved", handleHierSelectData); ??
I am missing something here?
I guess what I want to know is...when you have an event listener and you want the handler function to return something HOW do you catch it and where?
View Replies !
View Related
How To Call Function On Class Event Handler
Hi friends..i have simple question about how to call a function on a class but i dont know how to do it, would you mind to help me,please.
I have a class :
Code:
class MyClass{
private var lvSendState:LoadVars;
private var lvLoadState:LoadVars;
public function Test(){
trace("function Test Run");
}
public function LoadSomeThing():Void{
lvSend=new LoadVars();
lvLoad=new LoadVars();
lvSend.sendAndLoad("some url", lvLoad);
lvLoad.onLoad = function(){
//try to call function Test
Test(); //This is doesn't work
}
}
}
I try to call function Test on lvLoad.onload but i doesn't work,does any body tell me how to call it ? thanks in advance
View Replies !
View Related
Access A Super Class Function From Event Handler
Here is my Sub Class extending superClass. I just want to access a method of my superClass "createBG(width:String,height:String)" inside my subClass method "setXML()" but under the event Handler "xml.onload"
Please give me some suggestions about syntax or logic anything.
Class subClass extends superClass{
function subClass(){
trace("SubClass")
}
function setXml(){
var myxml:XML = new XML();
var mmX=myxml.load(url);
myxml.ignoreWhite=true;
myxml.onLoad=function(success){
// Here I want to access the super class method createBG(width:String,height:String);
//super.createBg(400,500); I have tried this. but no output.
}
}
}
View Replies !
View Related
Buttons Inside MC Not Working When Event Handler Function Is Assigned To MC
Please help!
I have a button on the stage that I assigned an event handler method to:
button1_bt.onRollover = function(){
animation1_mc.gotoAndPlay(10);
This is perfect. It plays the animation which is a drop down menu then stops in the dropped down state. However, I want "animation1_mc" to play it's pull up animation, starting on frame 21, when the MC is rolled off of. So I added this event handler method:
animation1_mc.onRollOut = function(){
animation1_mc.gotoAndPlay(21);
}
This also works, EXCEPT, the buttons inside the MC "animation1_mc" do not work! How can I have the pull up animation play on rollout o th e MC without disabling the buttons inside the MC???!!!
View Replies !
View Related
Designer Tries Code - Needs Basic Help (a Multiple Button Event Handler Function)
I know this is most inelegant and I'm wondering if there is an easy way to clean this up rather than repeating it 12 times. These are invisible buttons controlling movieclips underneath.
How would I write a function that would take care of all of them, given that the instance names of each object contains the same numeral within each set of methods?
(A fair number of eyes roll skyward about now - I'm a newb)
// button event handler methods
//------------
if (b1_mc._currentframe<4) {
b1_btn.onRelease = function() {
_root.gotoAndPlay("s1");
};
b1_btn.onPress = function() {
b1_mc.gotoAndStop(3);
};
b1_btn.onRollOut = function() {
b1_mc.gotoAndStop(1);
};
b1_btn.onRollOver = function() {
b1_mc.gotoAndStop(2);
};
}
//------------
if (b2_mc._currentframe<4) {
b2_btn.onRelease = function() {
_root.gotoAndPlay("s2");
};
b2_btn.onPress = function() {
b2_mc.gotoAndStop(3);
};
b2_btn.onRollOut = function() {
b2_mc.gotoAndStop(1);
};
b2_btn.onRollOver = function() {
b2_mc.gotoAndStop(2);
};
}
//------------
if (b3_mc._currentframe<4) {
b3_btn.onRelease = function() {
_root.gotoAndPlay("s3");
};
b3_btn.onPress = function() {
b3_mc.gotoAndStop(3);
};
b3_btn.onRollOut = function() {
b3_mc.gotoAndStop(1);
};
b3_btn.onRollOver = function() {
b3_mc.gotoAndStop(2);
};
}
//------------
if (b4_mc._currentframe<4) {
b4_btn.onRelease = function() {
_root.gotoAndPlay("s4");
};
b4_btn.onPress = function() {
b4_mc.gotoAndStop(3);
};
b4_btn.onRollOut = function() {
b4_mc.gotoAndStop(1);
};
b4_btn.onRollOver = function() {
b4_mc.gotoAndStop(2);
};
}
//------------ etc....
View Replies !
View Related
Event Handler Inside An Event Handler
i have a movie clip that is essentially a box when clicked can be dragged around and so forth.
ActionScript Code:
//AS for the box movie clip
on (press) {
startDrag(this);
}
on (release) {
stopDrag();
}
however inside the box i want a small button that should be able to close the box by turning it invisible (unless there is a better way to do this)
ActionScript Code:
//AS for the close button
on (press) {
setProperty("_root.box", _visible, false);
}
the box can be dragged but clicking the close buttons does nothing (just continues to drag the box). i think the problem here is since im using the press function to drag the box then the press function inside the clip never actually gets executed. is there a way around this or maybe a better way to create this effect? thanks.
View Replies !
View Related
Passing Parameters From Event Listener To Event Handler
Hi Chaps,
First of all, apologies as I know this question has been asked before, but I have spent the last twenty minutes reading this thread and still can't seem to figure out how to apply it to my situation - probably because I'm thick!
I have a number of objects which need to be rotated according to different parameters. I have a function which takes those parameters, then uses the tween class to handle the rotation. I'm then using the tweenEvent class to check for when the motion is complete. Then, I need access to those same parameters in the complete handler to do further operations. The problem I have is that the tween event class doesn't allow me to pass the parameters along to the cpmpleteHandler, so I'm stuck getting my parameters from the first function to the second function:
Code:
function rotate(parameters){
rotationTween = new Tween(object,parameter1,parameter2,........);
rotationTween.addEventListener(TweenEvent.MOTION_FINISH,completeHandler);
}
function completeHandler(e:TweenEvent){
//need access to the paremeters passed into the first function here!!
}
From reading the thread mentioned above, I have a feeling I may need a custom class to do this - please don't laugh but I've never written (or had the need to) write my own class before, so I really wouldn't know what to do. Any help greatly appreciated, but an actual code snippet which demonstrates this would be even better!
Ric.
View Replies !
View Related
Custom Event Handler For A Timer Event?
I understand how to create custom events in order to pass parameters to a function being called by an event listener. I can get this to work fine if the event is being dispatched within my own code. However, I don't get how to do this if the event is a built-in event being dispatched by a Flash object.
Specifically, I need to call a function and pass it parameters when a timer ends. I don't know how to change the information being sent by the Timer because it is a native Flash class rather than something I'm writing. Can someone please clarify how to do this?
View Replies !
View Related
Using Event.target With An Event Handler
Hi folks,
I'm looking for a more efficient way of doing the following:
Code:
function selectLevel():void{
levelSelect.level1.addEventListener(MouseEvent.MOUSE_DOWN,gotoLevel1);
levelSelect.level2.addEventListener(MouseEvent.MOUSE_DOWN,gotoLevel2);
levelSelect.level3.addEventListener(MouseEvent.MOUSE_DOWN,gotoLevel3);
}
function gotoLevel1(e:MouseEvent):void {
currentLevel = 1;
//load up level 1
}
function gotoLevel2(e:MouseEvent):void {
currentLevel = 2;
//load up level 2
}
function gotoLevel3(e:MouseEvent):void {
currentLevel = 3;
//load up level 3
}
As you can probably see, I have a movie clip called 'levelSelect' which contains three buttons - level1, level2 and level3. What I'm doing so far, is adding an event listener to each button, and then if any of them are clicked, it activates a different event handler function for each button.
However, as the only difference in the handler functions is the number of the level, and then assume I have 100 levels, this doesn't seem like very efficient coding!
So, how can I make it so that I have just a single event handler function which all the buttons use, and get it to recognise which level button was clicked? Effectively, I'm trying to do this:
Code:
function selectLevel():void{
levelSelect.level1.addEventListener(MouseEvent.MOUSE_DOWN,clickHandler);
levelSelect.level2.addEventListener(MouseEvent.MOUSE_DOWN,clickHandler);
levelSelect.level3.addEventListener(MouseEvent.MOUSE_DOWN,clickHandler);
}
function clickHandler(e:MouseEvent):void {
//somehow detect the level number 'n' from the instance name of the button, or the child number of the parent movieclip
currentLevel = 'n';
//load up level 'n'
}
I'm sure it has something to do with e.target, or e.currentTarget, but I can't get further than that!
Cheers,
Ric.
View Replies !
View Related
Using Movie Clip Event Handler Function, But Not For A Movie Clip
Let's say I have the following code:
----------------------------------------------
var initObj = new Object();
initObj.mood = "happy";
mc = attachMovie("mcBox","instBox",100,initObj);
mc.onPress = boxPress;
function boxPress() {
trace("Box mood: " + this.mood);
}
----------------------------------------------
Now, let's say there are times that I want to call boxPress() other than when the onPress event happens. Is there a way I can set up an object, give it a "mood" property, and then run boxPress() so that it uses my non-movieclip object instead of a movie clip?
View Replies !
View Related
Event Handler, Please Help :o)
Hey,
I'm desinging a website and I created the menu in a movie clip. The rest of the site, ex: home, pics, ect.. is on the main timeline. I used labels for home, pics, ect.. but I need an event handler that will let the buttons in the movie clip menu go to the labels on the main timeline. If anyone knows the event handler for this or has any ideas that could possibly help me. Please let me know. Thanks so much for you help.
- John
View Replies !
View Related
Event Handler
How can I add actions to a movieClip that is dynamically created?
I need my script to create a movieClip, load a picture into the movieClip, and add an onRelease event handler to this movieClip.
Can this be done??
View Replies !
View Related
Event Handler
I have a component placed on a movie clip that is its _targetInstanceName. In my component I want to catch an event of the _targetInstanceName. How can I do it?
View Replies !
View Related
Event Handler Help
I need some help with event handlers
you have a movie clip named "ball"
Code:
ball.onEnterFrame = function () {
this._y+=3;
}
This code goes on the timeline.
When the code is placed on the clip here is the error
Code:
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1:
Statement must appear within on/onClipEvent handler
ball.onEnterFrame = function() {
Total ActionScript Errors: 1 Reported Errors: 1
What would have to change in the code to place it on a clip?
Thanks
Ponyack
View Replies !
View Related
Event Handler
Hello,
I have a simple question,
I'm making a movie quiz and at the end i have an animation inside a movie clip and when the person gets to the last frame I want that animation to play but only one time instead of playing it 12 times per second so I would like to know if there is an event handler that does this, for example:
ActionScript Code:
onClipEvent(enterFrame){ //<--- this is the event handler want to replaceif(_root.Score ==100){_root.ball.gotoAndPlay("AdvancedM");}}
thanks
View Replies !
View Related
Terminate Event Handler
I'm using Colin Moock's event handler driven preloader (see below), but need to incorporate the ability to stop preloading (skip intro button) and load a new page in the browser. A simple goto action attached to a button doesn't work while the loader is chugging away. The command "break;" doesn't seem to work with event handlers, and a simple skip intro button with a getURL(~, _self) action doesn't jump until the preloader finishes.
I've tried (unsuccessfully) to pass a variable into the named movieclip ("_root.preloader.skip = 1;") to which this script is attached, but it seems to ignore it, e.g., if (skip > 0){gotoAndStop("end");}
Any suggestions?
//The Preloader
onClipEvent (enterFrame) {
loaded = _parent._framesloaded;
if (loaded>0 && loaded == _parent._totalframes && loading != "done") {
_parent.gotoAndPlay("start");
loading = "done";
}
percentDone = Math.floor((_parent.getBytesLoaded()/_parent.getBytesTotal())*100);
loadStatus = percentDone+"% complete";
bytesLeft = Math.floor((_parent.getBytesTotal() - _parent.getBytesLoaded())/1000);
displayBytes = bytesLeft + "k remaining";
loadBar._xscale = percentDone;
}
View Replies !
View Related
What Event Handler Can I Use For Hover?
I made a little scrolling textarea in Flash MX and I'm attempting to create an effect.
I made two UP and DOWN buttons. Currently I have to press them UP and DOWN to get the text to scroll. How can I get so that I only have to HOVER over the button and it will keep on scrolling?
EXAMPLE: http://www.sohh.com/dev/Flash_Text_A...06-06-2002.swf
http://www.sohh.com/dev/Flash_Text_A...06-06-2002.fla - SOURCE CODE
[Edited by ibeblunt on 06-08-2002 at 12:16 AM]
View Replies !
View Related
Movie End Event Handler
I have six sound files (all separate .swfs). Each file lives in its own frame with a stop (); script attached to each frame.
I want to give the user the option of listening to a single sound file, or listening to them all in succession. Does anyone of a suggestion for a script to handle this?
Is there an event handler that addresses the end of a sound or a movie clip? I'm sure there is, and if I knew that I could figure out the rest on my own.
Thanks in advance!
View Replies !
View Related
'onmousemove' Event Handler
I have attached the 'onmousemove' event handler onto a movie clip (I want the movie to goto the next scene if the mouse is moved). However it does not seem to work...do I have to work out the mouse coordinates first or something? If anyone could provide me with the script I would be very greatful!
Many Thanks
Elliot
View Replies !
View Related
'onmousemove' Event Handler
I have attached the 'onmousemove' event handler onto a movie clip (I want the movie to goto the next scene if the mouse is moved). However it does not seem to work...do I have to work out the mouse coordinates first or something? If anyone could provide me with the script I would be very greatful!
Many Thanks
Elliot
View Replies !
View Related
Onquit Event Handler?
hi, is there any way in flash to use an on_quit event? i would like to have short movie clip (e.g. a company logo) displayed when the user quits the flash player (standalone). just like seen with the macromedia director stuff.
thanks
hyper
View Replies !
View Related
OnRelease Event Handler
I'm dynamically creating thumbnail images, by using createEmptyMovieClip(), and then loading the jpg's into those empty clips. I want these to be clickable buttons, so after they are created and loaded, I'm using this code to attempt to attach an action:
(inside a for loop, so i is being incremented...)
...
{
clip = "clip" + i;
loader[clip].loadMovie(imgList[i]);
loader[clip].onRelease = function()
{
trace("test action");
};
}
...
each movie clip is getting a different image loaded, so the targeting of the movie clips (loader[clip]) works, but for some reason, no tracing occurs when i click on any of them.
Has anyone else had problems using onRelease = function() on movie clips? I think I'm missing something simple here, but can't figure it out...
View Replies !
View Related
OnRelease Event Handler
I'm dynamically creating thumbnail images, by using createEmptyMovieClip(), and then loading the jpg's into those empty clips. I want these to be clickable buttons, so after they are created and loaded, I'm using this code to attempt to attach an action:
(inside a for loop, so i is being incremented...)
...
{
clip = "clip" + i;
loader[clip].loadMovie(imgList[i]);
loader[clip].onRelease = function()
{
trace("test action");
};
}
...
each movie clip is getting a different image loaded, so the targeting of the movie clips (loader[clip]) works, but for some reason, no tracing occurs when i click on any of them.
Has anyone else had problems using onRelease = function() on movie clips? I think I'm missing something simple here, but can't figure it out...
View Replies !
View Related
Setinterval - Event Handler Help
Help. I need help with code to have this read in as I start my program. I have heard about setinterval, but need help with the code to make it work. Also is this the way on should go?
on (release) {
_root.SQLSelect = "SELECT * from trade WHERE FieldID = 2";
fscommand("flashstudio.selectfromdb", "SQLSelect");
fscommand("flashstudio.getfieldfromdb", ""tradedesc","1",desc2");
fscommand("flashstudio.getfieldfromdb", ""discount","1",discountb");
View Replies !
View Related
Combine Var With Event Handler
How do I use the variable path correctly with my .onPress ...
function drag()
{
path = ("_root.hold3.global_mv");
path.onPress = function()
{
startDrag(path);
}
path.onRelease = function()
{
stopDrag();
}
}
drag();
I just tried Eval(path) and it works but is this correct? I don't want to use my Flash4 syntax.
View Replies !
View Related
...please Help Problems With An Event Handler
Hi buddies!
I'll try to explain as easy as possible this problem:
Ive got a movie where fireflies are flying in the night. The idea is that when I touch 3 fireflies, they go into a bottle (we say... when I catch them). When the 3 fireflies are into the bottle, I need to start an animation (it's basically an image of a dawn that represents that the day has come).
First, I created a variable that contains the info about how many fireflies are into the bottle. Everytime that one of the bugs gets into the bottle, I increase the value +1.
So I create an event handler (onEnterFrame) that evaluates when the variable reaches the value of 3. If the variable = 3, then the animation begins...
The problems is that I cannot make the animation start... I dont know if it related to the eventhandler code, or something else... I spent an afternoon trying to solve it but I couldn't.
Ive attached the file (MX format) so you can see the whole thing...
Take a look buddies!!!
I need some opinions please!!!
View Replies !
View Related
Loadmovie Using An Event Handler? Or What?
Hello and thank you all in advance.
Dumb question. Can you load an external swf or jpeg file into a target by having a button on the main timeline with on(press)? I've noticed that in the forum several answers regarding loading the movie were answered but I would like to trigger the file by using an event handler (eg on(press)).
Thanks again!
View Replies !
View Related
Creating New Event Handler For MC
In a kiosk application (with NO mouse action) I try to mimic the action of buttons...with movie clips.
I was wondering if that would be possible to create new event handler for MC?
So that, by script, I could tell something like:
my_mc.selected = true
my_mc.focused = true
then have an event handler function like:
my_mc.onSelected = function () {
trace ("button is pressed");
}
my_mc.onFocused = function () {
trace ("button is on focus");
}
So:
1) a way to give a state to a movieclip (like "focused", "pressed"...)
2) then an event handler...to handle corresponding function
Would you please have an idea on how I could achieve this?
Thanks a lot!
View Replies !
View Related
Custom Event Handler
hi:
i was wondering if it was posible to make a custom event handler, i have a scene and i duplicate a MC a lot of times and each duplicated MC has its own code, so the scene is getting a little slow, so i was wondering instead of using the enterFrame event handler i could use something like this
onClipEvent(this._x<100){
do this
}
or instead of the this._x<100 some other condition
thanks i have flash 8 and i am using actionscript 2
View Replies !
View Related
XML Event Handler Problem
I'm working with AS 2.0.
Well I have the xml load in my constructor so I know I make the call to load the xml before I call the getTeam function but I've read that the xml won't necessarily load right away or something like that. I've put an if statement that takes the success parameter from the xml.onLoad function so I thought that guarenteed that all the data would load before moving on to other functions but maybe that isn't the case. Is there anyway to make sure that the xml has loaded completely before anything else is done? When I trace the teams array inside the event handler it outputs the Objects in the array but when I try tracing the teams array anywhere else but in the event handler it gives me undefined.
Here's the code for my class and the test code follows it:
Code:
class League{
private static var numberOfTeams:Number=32;
private var teams:Array;
private var games:Array;
private var numberOfGamesPlayed:Number;
public function League()
{
teams=new Array();
games=new Array();
var parent=this;
var xmlInput:XML=new XML();
xmlInput.ignoreWhite=true;
xmlInput.onLoad=function(success)
{
if(success)
{
for(var i=0; i<xmlInput.firstChild.childNodes.length; i++)
{
var t:Team=new Team(xmlInput.firstChild.childNodes[i].attributes.name,
xmlInput.firstChild.childNodes[i].attributes.totalGames,
xmlInput.firstChild.childNodes[i].attributes.wins,
xmlInput.firstChild.childNodes[i].attributes.losses,
xmlInput.firstChild.childNodes[i].attributes.pointsForPerGame,
xmlInput.firstChild.childNodes[i].attributes.yardsForPerGame,
xmlInput.firstChild.childNodes[i].attributes.thirdDownPercentage,
xmlInput.firstChild.childNodes[i].attributes.penaltyYards,
xmlInput.firstChild.childNodes[i].attributes.pointsAllowedPerGame,
xmlInput.firstChild.childNodes[i].attributes.yardsAllowedPerGame,
xmlInput.firstChild.childNodes[i].attributes.interceptions,
xmlInput.firstChild.childNodes[i].attributes.forcedFumbles,
xmlInput.firstChild.childNodes[i].attributes.puntReturnAvg,
xmlInput.firstChild.childNodes[i].attributes.kickReturnAvg);
parent.teams.push(t);
}
}
}
xmlInput.load("NFLTeamStats.xml");
var xmlInput2:XML=new XML();
xmlInput2.ignoreWhite=true;
xmlInput2.onLoad=function(success)
{
if(success)
{
for(var j=0; j<xmlInput2.firstChild.childNodes.length;j++)
{
for(var k=0; k<xmlInput2.firstChild.childNodes[j].childNodes.length; k++)
{
var g:Game=new Game(xmlInput2.firstChild.childNodes[j].attributes.id,
xmlInput2.firstChild.childNodes[j].childNodes[k].attributes.id,
xmlInput2.firstChild.childNodes[j].childNodes[k].attributes.winner,
xmlInput2.firstChild.childNodes[j].childNodes[k].attributes.loser,
xmlInput2.firstChild.childNodes[j].childNodes[k].attributes.margin,
xmlInput2.firstChild.childNodes[j].childNodes[k].attributes.total);
games.push(g);
}
}
}
}
xmlInput2.load("NFLGames.xml");
}
public function getGamesPlayed()
{
numberOfGamesPlayed=0;
var xmlInput3:XML=new XML();
xmlInput3.ignoreWhite=true;
xmlInput3.load("NFLGames.xml");
trace(xmlInput3.firstChild.childNodes[0].attributes.id);
xmlInput3.onLoad=function()
{
for(var i=0; i<xmlInput3.firstChild.childNodes.length; i++)
{
trace("outer loop");
for(var j=0; j<xmlInput3.firstChild.childNodes[i].childNodes.length; j++)
{
trace("inner loop");
numberOfGamesPlayed++;
trace(numberOfGamesPlayed);
}
}
}
return numberOfGamesPlayed;
}
public function getTeams():Array
{
trace(teams.length);
var teamsArray:Array=new Array();
teamsArray=teams.slice();
trace(teamsArray.length);
return teamsArray;
}
public function getGames():Array
{
var gamesArray:Array=new Array();
gamesArray=games.slice();
return gamesArray;
}
}
Code:
var l:League=new League();
trace(l.getTeams());
View Replies !
View Related
Event Handler In Nested Swf
I have a combo box component that works fine when tested alone. It breaks, however, when a parent swf loads it. The code (shortened for brevity) of the child swf containing the combo box is:
Code:
// Create listener object.
var cbListener:Object = new Object();
// Create event handler function.
cbListener.change = function (evt_obj:Object) {
switch (evt_obj.target.selectedItem.label) {
case "Donor Recruitment":
gotoAndStop("recruiting"); break;
case "Donor Screening":
gotoAndStop("screening"); break;
case "Introduction":
gotoAndStop("intro"); break;
default:
gotoAndStop("intro"); break;
}
}
// Add event listener.
quickLinks.addEventListener("change", cbListener);
quickLinks.dropdownWidth = 150;
quickLinks.setStyle("backgroundColor", "0xDDDDDD");
quickLinks.setStyle("fontSize", 11);
// Add Items to List.
quickLinks.addItem({data:1, label:"Introduction"});
quickLinks.addItem({data:2, label:"Donor Recruitment"});
quickLinks.addItem({data:3, label:"Donor Screening"});
Any help would be greatly appreciated!
View Replies !
View Related
Event Handler Misery
Hey guys,
I am having trouble with event handlers. I have the following code:
var object:Object=event.target;
var dropTween=new Tween(object, "x", None.easeNone, object.x, myTarget.x, 0.7, true);
var dropTween2=new Tween(object, "y", None.easeNone, object.y, myTarget.y, 0.7, true);
dropTween.addEventListener(TweenEvent.MOTION_FINIS H, bounce(object));
Then:
function bounce(event:TweenEvent, dO:Object):void
{
trace("funtion: bounce");
if (currentTotal>targetTotal)
{
var bounceTween=new Tween(dO, "x", None.easeNone, dO.x, startX, 0.7, true);
var bounceTween2=new Tween(dO, "y", None.easeNone, dO.y, startY, 0.7, true);
}
}
But it won't let me pass the value to the event handler... How can I get around this? Do I need to use a global variable, or is there a better way?
View Replies !
View Related
Creating New Event Handler For MC
In a kiosk application (with NO mouse action) I try to mimic the action of buttons...with movie clips.
I was wondering if that would be possible to create new event handler for MC?
So that, by script, I could tell something like:
my_mc.selected = true
my_mc.focused = true
then have an event handler function like:
my_mc.onSelected = function () {
trace ("button is pressed");
}
my_mc.onFocused = function () {
trace ("button is on focus");
}
So:
1) a way to give a state to a movieclip (like "focused", "pressed"...)
2) then an event handler...to handle corresponding function
Would you please have an idea on how I could achieve this?
Thanks a lot!
View Replies !
View Related
Help Adding Event Handler
Hi,
I have in the first frame of a flash document the following code:
attachMovie("mcImage","image1",1);
image1._y=0;
image1._x=400;
image1.onEnterFrame = function() {
this._x-= 1;
trace("moved");
}
I have the linkage for mcImage set to Export fir ActionScript and Export in first frame.
When I test it, the instance moves to the right location, but the onEnterFrame function only runs once (it says "moved" once in the output window). I'm trying to get the instance to scroll across the screen.
Shouldn't the onEnterFrame function run as often as my frame rate?
Thank you.
View Replies !
View Related
Dynamic Event Handler Help
So I found this really great snow effect, but its coded for flash 5.
Because of the onClipEvent (enterFrame) code, I can't make it stop after 15 seconds. Well, I don't know HOW to make it stop after 15 seconds. does anyone? if not, can someone help me throw this code into a function so that I can apply a getTimer(); to it and stop it after 15 seconds?
Heres the code:
onClipEvent (load) {
//variables
width = 305;
height = 250;
//random x,y, and alpha
this._xscale = this._yscale=50+Math.random()*100;
this._alpha = 20+Math.random()*50;
//random x and y for flakes
this._x = -width+Math.random()*(3*width);
this._y = -10+Math.random()*height;
//speed and trigonometric value
i = 1+Math.random()*2;
k = -Math.PI+Math.random()*Math.PI;
rad = 0;
}
onClipEvent (enterFrame) {
// horizontal movement
rad += (k/180)*Math.PI;
xmovement = _root._xmouse;
this._x -= Math.cos(rad)+(xmovement-(width/2))/50;
// vertical movement
this._y += i;
// remove clips when they misbehave (overstep boundaries)
if (this._x>(width+50)) {
this._x = -45;
this._y = Math.random()*height*2;
}
if (this._x<-50) {
this._x = width+45;
this._y = Math.random()*height*2;
}
if (this._y>=height) {
this._y = -50;
this._x = -width+Math.random()*(3*width);
}
}
View Replies !
View Related
Problem With Event Handler
Hi, I am new to programming in Flash.
My problem is that whenever I try to write an event handler for a simple button class, it always says that the statement (which is actually an event handler that I wrote) needs to be within an event handler. My code is not being read as an event handler.
I've attached the .fla file for the button class I am trying to create and I put it in a zip file.
Whatever help anyone can provide would be greatly appreciated.
Sam
View Replies !
View Related
Event Handler Problem
folks,
i'm trying to return some xml data assigned to a local private variable via an event handler function, and then have that value returned via a getter but i seem to be losing the data upon exiting the event handler function:
Code:
loader.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("data.xml"));
private function onComplete(e:Event):void {
_data = loader.data; // or e.target.data, doesn't make a diff
}
// however...
public function get Data():XMLList {
return _data; // returns null
}
why am i losing the information stored in _data upon exiting onComplete(), if i'm storing it as a local private variable? this is what i want to do:
Code:
// object that contains code above
var xmlData:XMLData = new XMLData();
trace (xmlData.Data); // should return xml data
thanks,
n.
View Replies !
View Related
Timer Event Handler..
I have a function that runs on a timer event something like the following:
Code:
playTimer=new Timer(100,0);
playTimer.addEventListener(TimerEvent.TIMER, mousePlayer);
playTimer.start();
function mousePlayer(evt:Event):void {
if (stage.mouseX>stageMid) {
if (currentHFrame<(hSkidArray.length-1)) {
currentHFrame++;
removeChild(hSkidArray[prevHFrame]);
addChild(hSkidArray[currentHFrame]);
prevHFrame=currentHFrame;
}
} else if (stage.mouseX<=stageMid) {
if (currentHFrame>0) {
currentHFrame--;
removeChild(hSkidArray[prevHFrame]);
addChild(hSkidArray[currentHFrame]);
prevHFrame=currentHFrame;
}
}
}
Theres an array of 30 display objects, and what its doing is checking for the mouse position and incrementing through the list based on mouseX > or < stageWidth/2. Fairly straight forward.
The problem is it seems to be really quickly running through all the increments based on mouseX every time the timer event fires. Seems obvious but it should test once each time, whereas it seems to be running looping the function continuously whenever the event is fired - is this making sense?
Any clues would be appreciated.
[edit] Just to add, it runs fine on an EnterFrame event but i needed more control so i used Timer.
View Replies !
View Related
Removing Event Handler
I've added an event handler to a MC.
ActionScript Code:
_root.frame.photo_frame.onPress = function(){...
Now I want to remove it - not just clear out the function. I don't want there to be an event handler (onPress) for this MC at all.
Any ideas? Thanks in advance!
View Replies !
View Related
Help On Dynamic Event Handler
Hi thr!
This is what I have:
1 movieclip with the following script on it:
onClipEvent (load) {
divalpha = 5;
_alpha = 0
}
onClipEvent (enterFrame) {
if (this._parent.barra_nav1._x <=350) {
_alpha += (endalpha-_alpha)/divalpha;
endalpha = 100
}
}
Which means that my mc wait till other movie (barra) reaches a certain point and then fades in.
What I need to accomplish:
I need that after this "marvelous" fading in, if the user rollover the mc it fades back to 20% alpha using the same formula and fades back to 100% when the user rollout.
As I´ve declared in the enterFrame that the alpha is equal to 100% I´m not getting the results I need.
Ive been searching for tutorials on Dynamic Event handlers with no results but I'm sure there most be a way to overwrite the first enterFrame...
HELP PLEASE!!!!!!!
Thx in advance
View Replies !
View Related
Mc Out Of Scope Event Handler
TIA,
I have two event handlers on the Main Timeline.(attached at the bottom)
Also on the Main Timeline, there is an outerMC(2frames), which contains, a innerMC1(frame1) and an innerMC2(frame2).
With the event handler on the Main Timeline, when the nested movieclip is no longer under the playhead, the event handler goes out of scope and stays out of scope, even if the playhead is returned to the firstframe, via the simple on() {prevFrame();} button.
This seems to be very odd, a parent function, does not go out of scope, when the playhead moves within a nested movieclip.
How can I have centralized event handler code on the Main Timeline and be able to address nested movieclips regardless if that movieclip exists on the first frame or not.
code:
Attach Code
outerMC.innerMC1 = function (){ this._parent.nextFrame();}
outerMC.innerMC2 = function (){ this._parent.prevFrame();}
View Replies !
View Related
Custom Event Handler
I am trying to make a custom event handler to check to see when the XML data is loaded into an object in my class so it can be accessed by the instance in an FLA. I made the class below to extend Events. I am planning on using a timer to keep checking to see when it is loaded. I can't put the checking logic into the base class because when the class runs, the XML object is there. It is a question of when it is available to the instance of the class. So, do I have to put the timer code in the FLA? Can I somehow put the timing logic into the handler as? Any help on the best way to do it....I've gotten it to work in the FLA but I hate having that code out there in the FLA if I can do it elsewhere in a class...
Thanks in advance!
Attach Code
// Can I put handler logic - timer checking logic - in here somehow and have it check for the instance?
package handlers{
import flash.events.Event;
public class xmlObjectEvent extends Event{
public static const XMLOBJECTLOAD:String = "XML Object Load";
public function xmlObjectEvent(type:String):void{
super(type);
}
public override function clone():Event{
return new xmlObjectEvent(type);
}
}
}
View Replies !
View Related
|