Need to turn on 51 event listeners
I'm trying to upgrade an old AS2 Flash that had 51 buttons on it that were simulating the buttons on a keypad. They each had a script on them with an onClick action. Since they are named sequentially, b1 through b51, I thought I could use a for loop to start an event listener on each one. This is the part of the code that I set up to do it. The problem is that it seems to be seeing it as a string rather than an instance name.
var q;
var i:Number;
for (i=1; i<=51; i++)
q = "b" + i.toString();
addButton(q);
function addButton(turnItOn){
turnItOn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
trace(turnItOn);
I get an error saying the "value is not a function" for MainTimeLine/addbutton(). If I comment out the line where it adds the event listener, it traces b1 through b51. Any ideas on how to fix this?
Thanks,
Jeff
use:
var i:int;
for (i=1; i<=51; i++)
this["b"+i].addEventListener(MouseEvent.CLICK,fl_MouseClickHandler);
Similar Messages
-
Removing Event Listeners - Are they needed all the time
My goal is to increase the performance of my project so I would like to know if it is always a good idea to remove event listeners. More specifically, lets say I have a movie with severals scenes and several frames within those scenes. Each one of the frames has an event listener:
Example:
Scene 1
Frame 1 (EventListener)
Frame 2 (EventListener)
Frame 3 (EventListener)
Frame 4 (EventListener)
Scene 2
Frame 1 (EventListener)
Frame 2 (EventListener)
Frame 3 (EventListener)
Frame 4 (EventListener)
Questions:
Does Flash continue to listen for an event in Scene 1/Frame 1 when the playhead has moved to Scene 1/ Frame 2?
Or does Flash just listen for the events when the playhead is in a particular frame only?
Should I remove the event listener once I leave a particular frame (should there be remove event listeners on each frame)?Just mentioning, the addEventListener comes with a parameter you can set to true or false called a weak reference. On desktop flash apps it can become time consuming to constantly remove listeners, especially when things drop off the display list frame to frame. You can mark them for automatic garbage collection by using the weak reference property.
e.g.
Credits_bnt.addEventListener(MouseEvent.CLICK, goCredits, false, 0, true); // set weak reference to true (e.g. remove when no references exist anymore automatically)
Eventually garbage collection will remove that reference automatically when there's nothing left on the display list or in memory to use it.
However, if this is targeted at mobile, you absolutely want to remove the reference as soon as possible when it's not needed for memory conservation. On a desktop it's not that big of a deal. -
Screen cracked, Need to turn phone off completely.
Off course, less than a week after my boyfriend gets this phone, he drops it and the screen cracked. We DO have insurance, but have to wait a week till payday for the deductible. Here is my problem.
Screen is cracked, phone is still on. I need to turn it off, as the alarms he has set for work keep sounding and are a pain to stop, as he has multiple each day. I know I can wait for the battery to die, of of course, BUT
I've read that I can do what is comparable to a battery pull with the volume down + power button for 10 seconds. I have done this, but it seems to restart rather than turn off. Is this what that action should do? Or am I doing it wrong. If this is what the action should do, am I out of luck until the battery dies?This is what I found in the manual, page 55 in the Troubleshooting area for your device...
Crash recovery
In the unlikely event that your smartphone stops
responding to touches and key presses, try a forced
reboot—press and hold both Power and the down
volume key for 10 seconds.
http://cache.vzw.com/multimedia/mim/mot_droid_razr/droid_razr_manual.pdf -
Help me I'm trying to create event listeners
I am trying to create event listeners
Whenever any keyboard event occurs the string s gets appended by a,c
or p.At the end of the program its supposed to print value of s
But s always happens to null.Please tell me how to correct it....so
that detection is possible for any case
import java.io.*;
import java.awt.event.*;
public class trial {
int x;
public static String s;
//OutputStream f1=new FileOutputStream("file2.txt");
public static void keyReleased(KeyEvent e)
s=s+"a";
public static void keyPressed(KeyEvent e)
s=s+"c";
public static void keyTyped(KeyEvent e)
s=s+"p";
public static void main(String args[])
throws IOException
char c;
BufferedReader br =new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Entercharactes,'q' to quit.");
do
c=(char)br.read();
System.out.println(c);
while(c!='q');
// for(int i=0;i<s.length();++i)
System.out.println(s);I suggest looking at the java tutorial. Your code completely misses the mark and you need to see examples.
-
Using Multiple Event Listeners
Hi,
I have a movielcip (A) class in which I have used a Tween class effect on a child movieclip (B) scrollRect. The (B) Movieclip in turn has several movieclips whose have tween class effect being executed on thier child movieclips.
the tweens are all unique to each movieclip
and the event listeners are taken off once completed.
This works all well and good in FLASH IDE...
My problem arises when I try to view this in a browser on a Windows XP
it doesnt work in
Opera Version 9.63
Firefox 2.0
and Google Chrome 2.0
The only browser it works fluently in is
Internet Explorer 7.0.5
What is happening in most cases it that the animation appears to "stick" but i think what may be happening is the listening or removal of the event listeners. The animations are left incompleted.
Is there any rule of thumb when using multiple event listeners?
here is a snippet of some of my code
on click event from movieclip (A)
private function scrollToSlidePrev(e:MouseEvent) {
if (((slideIndex - 1) >= 0)) {
nextButton.mouseEnabled = nextButton.enabled = previousButton.enabled = previousButton.mouseEnabled = false;
var position:Number = 0-SLIDEAREA.width;
var slide1:TileListSlide = slides[slideIndex] as TileListSlide;
var slide2:TileListSlide = slides[--slideIndex] as TileListSlide;
scrollSlide(position,slide1,slide2);
tween animation in movieclip (A) on (B)
private function scrollSlide(pos:int,slide1:TileListSlide,slide2:TileListSlide) {
slide1.resizeSlideTo(0.6); // execute tween on child movie clips in B
slide2.resizeSlideTo(1); // same as above;
var rect:Rectangle = sliderMc.scrollRect;
var tween1:Tween = new Tween(rect,"x",Regular.easeOut,rect.x,rect.x + pos,3,true);
tween1.addEventListener(TweenEvent.MOTION_CHANGE,setSliderScroll,false,4);
tween1.addEventListener(TweenEvent.MOTION_FINISH,toggleButtonEnabled,false,3);
tween animation in movieclip (B) children
public function resizeSlideTo(sc) {
var m:Matrix = tileList.transform.matrix as Matrix;
var p:Point = new Point (m.a, 0);
var tween2:Tween = new Tween(p,"x",Regular.easeOut,p.x,sc,3,true);
if (numericStepper != null) {
if (sc != 1) {
numericStepper.visible = false;
tween2.removeEventListener(TweenEvent.MOTION_FINISH,showStepper);
if (sc === 1) {
tween2.addEventListener(TweenEvent.MOTION_FINISH,showStepper,false,2);
tween2.addEventListener(TweenEvent.MOTION_CHANGE,setScaleOnScroll,false,3);
here is the link
http://visual_admin.web.aplus.net/ticker/ticker_widget.html
the effect disables and re-enables the buttons when its done.... then the listeners are removed.
each one with the exception cretes its own unique tween (obviously this is a custom class built as each clip)
i really don't know what to make of it guysapparantly making the tween a property of the class rather than a random variable in a function worked.....go figure
-
Loading/Unloading a .swf that adds event listeners to the Stage
Hi all,
Disclaimer
Apologies if I suck so bad at using forum search that the answer to this is on page 1 somewhere; I tried...
Question
I am loading and unloading a .swf to which I do not have source code access. This .swf places several event listeners on the stage, as far as I can tell. When the .swf is unloaded, the event listeners placed upon the stage still seem to be in effect. Using unloadAndStop doesn't seem to do it, and I have to target Flash Player 9, anyway, so can't really use it. Is there any other way I can keep this external .swf from holding onto my main movie's stage?
Additional info
All eventListeners and references being set by my code are removed.
I've managed a little contact with the author of the .swf:
I've requested he provide a dispose() method I can call to get all the listeners removed, and send an updated .swf.
He's suggested that I should be able to avoid the problem by loading into a unique ApplicationDomain. I'm not terribly familiar with this, but have given it a try without much success. Is this a valid solution - can I really protect my 'stage' by properly using ApplicationDomains - or do I need to persist in trying to get a public dispose() method built in?
Thanks in advance!
Cheers, Johnthanks for reply sir
sir actually, i have not any problem with loading any file but i need to go back to intro.swf file when i click on clsbtn of main.swf, i want unload the main.swf file and panel.swf file
actually i did was, i have intro.swf file and there is button by clicking load main.swf file (where is timeline controling butons) and in the main file automatically load panel.swf file ( where is all animation)
its all play gud , no problem
but my problem is there is a clsbtn in main.swf file and when i click on that button everything should be unload and it should return on the previous position in intro.swf
i hope u understand what i am trying to say -
Spry event listeners with dynamic form elements
Hi ,
I am trying to implement spry event listeners with a form that has dynamic check boxes and text field name. I now i can get the elements in a var and loop through with a normal function but can this work for spry events listenersShort answer is yes. But I have a feeling that you need further assistance, in which case give us a URL to a page that you want to apply the event listener to.
-
All event listeners and models in one file?
I have one java file for all my event listeners of a programm and one java file for all my models. Is this good?
I create instances with new AllInOneHandler.MouseHandler() for example.
Or should I have one file for each event and each model?Hi,
you should have one file for each class or interface - this gives you best control and reusability. Also when you have javadoc-comments in it, big files with many classes in it will become hard to edit.
When using one file for each class or interface you can import only the needed classes or interfaces instead of importing whole packages - so it is easier to see, what is exactly imported. As so a good structured application has many classes, where each of them is small (and in an own source file), you will have less problems during the evolution of your classes this way.
If you want to group some classes, why not use sub-packages for this purpose?
greetings Marsian -
Remove Event Listeners (at the right time)
I have a app which loads multiple flv's, I also have a timer
(digial) which shows how long the movie has been played for. The
problem is that whenever i load and new move (through the same
"loadVideos()" function, the timer variables ("lagTime", "endTime")
are not reset (even though the correct variables are being passed.
I believe it has something to do with the event listeners which are
being used to load the movies. How can i clear all the listerner
before reloading the movies?
Here is a code snippet:
Thanks in advanceThanks, kglad
Yes it traces 'endTime' but what happens is that when i play
the first movie is will display for example ("40,40,40,40" etc...)
until the video stops playing. If i load another movie it will then
trace ("40, 20, 40, 20, 40" etc...) so i need to kill the
listereners and reload the variables.
Jake -
Is there a way to clear ALL event listeners, stop all movie clips, etc?
Is there a syntax for this?
I have a movie that has 15 frames. Each frame has embedded movie clips within movie clips, tons of animations and event listeners. None is needed except when they are on the stage, on the frame. However, the animations continue even when the frame is left.
For instance, I have a frame that has a dynamically rendered animation of leaves falling from a tree. When the frame is left, the leaves continue to fall.
There are many instances of this type of thing happening.
Ideally, I would love to just be able to clear everything when a new frame is loaded, since none of the animations or event listeners need to carry over from one frame to another.
Is there a way to do this without the thousands of lines of code it would take to manually remove every single animation and event listener and sound, etc, from the stage?
Thanks so much!!
Amberyou have to manually do that.
or, you could convert each frame to a swf. load each swf when needed and, if you're publishing for fp 10+, you can apply unloadAndStop() to kill all streams in the loaded swf and ready those assets for gc. -
Multiple Event Listeners on same property?
I have assigned two event listeners to the same property:
full_loader1.contentLoaderInfo.addEventListener (Event.COMPLETE, fullLoaded1);
full_loader1.contentLoaderInfo.addEventListener (Event.COMPLETE, tweenOut2);
So far it works fine. I am just wondering if there is a hidden penalty that I am eventually to learn about.Thanks for the answer.
... but i would call tweenOut2() from fullLoaded1().
I had that first, but got a dialog telling me that "tweenOut2" needs to be called from its original caller. That's why I came up with the double Event Listener solution. -
JSP Event Listeners ????
Hi,
Do event listeners exist in JSP (like in SWING)? Is there something similar in JSP?
Any info would be appreciated.Hi,
Do event listeners exist in JSP (like in SWING)? Is
there something similar in JSP?
Any info would be appreciated.
There are no event listeners in a JSP. Once the JSP page is loaded the browser does not know it is a JSP. It is an HTML file as far as the browser is concerned.
Use JavaScript events if you need event handling in the loaded JSP page.
Most HTML tags have events of some sort. For example, a form INPUT tag has onBlur, onChange, onFocus, and onSelect events. Check an HTML tag reference and a JavaScript or JScript manual for details.
MSIE 5 has more events than Netscape 4. I do not know about Netscape 6 and later. -
Java event listeners. newbie
hi guys
i have this simple applet with 2 threads and a scrollpane in the first thread which scrolls some test data in a textarea.
i need to add an event listener to capture the movement of the vertical scrollbar. the examples i have seen online all use a seperate class for event listening.
i was wondering if i am able to incorporate it all into this 1 class below, or must i use a seperate event listening class?
any code would be welcome! thanks in advance.
import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
public class DisplayApplet extends Applet {
public static JTextArea data = new JTextArea("", 20,100);
public static JScrollPane dataScroll = new JScrollPane();
public void refreshData() {
System.out.println("refreshing data..");
public void scrollDown() {
System.out.println("scrolling down..");
public void scrollUp() {
System.out.println("scrolling up..");
public void start() {
Runnable displayThread = new Runnable() {
public void run() {
System.out.println("Hello from thread 1");
data.setFont(new Font("Courier", Font.PLAIN, 10));
for (int i=0;i<100;i++) {
data.append("test\n");
dataScroll = new JScrollPane(data);
DisplayApplet.this.add(dataScroll);
Runnable dataThread = new Runnable() {
public void run() {
System.out.println("Hello from thread 2");
new Thread(displayThread).start();
new Thread(dataThread).start();
}i understand your frustration, but you must also
understand that i am a java newbie. there was a time
when you didnt know any java.I only get frustrated if people don't listen to what I say, newbie or not.
im just trying to work
my way up to your knowledge and one of my initial
tasks is to write a multithreaded application with
event listeners.So go ahead.
http://java.sun.com/docs/books/tutorial/uiswing/events/index.html
may be easy for you, but it is a
little overwhelming for me as a point of entry into
java. thats all. thats why i asked if my classes were
arranged in the correct structre. i didnt know. i
need advice. i didnt say that was what i was going to
use.
any suggestions are welcome.I provided suggestions for structure. I provided suggestions for a listener to use. What else do you want? -
Training Need - TN in Training and Event Management
Hi
Did any one worked on Training Need (TN) in Training and event management? I have the below question.
For France there is a legal requirement to capture some 1.6 % of the employee annual gross salary towards training cost. So where to record the training cost of the employee in Training and event management and is there any link with payroll.
Logically it sounds as it does. but where and how is it connected with payroll.
Please revert if you know the solution.
Brs
Kenu.Hi
In Table V_T77TNM_DC
We need to have the below entries
TNM CL_HRTNM_VALO_COMPUT_GUI_FR
TNM HRTNM00_REPMOD CL_HRTNM_VALO_COMPUT_GUI_FR
TNM MP168400 CL_HRBAS_INFTY_1684_GUI_FR
TNM RPCTNM9S_REP CL_HRTNM_INFTY_1036_GUI_FR
Regards
Kenu -
Need to turn off iMessage for an iPhone that no longer works
My daughter broke her iPhone and the motherboard is fried. We got her an Android as a temporary phone until she is due for an upgrade in a few months. The problem is that when we try to text her on the new Andriod, on our iPhones (and any other iPhone that tries to text her) it still sends as an iMessage. Therefore she cannot receive any texts from us unless we turn off our iMessage (which causes us not to be able to receive other iMessages of course!). We went to the Sprint store, and they told us that we would need to turn off the iCloud for her phone, since Apple is recognizing it as still on and associated with her number. I cannot figure out how to do that since we can't access the phone settings. She is traveling this week alone with other family and I really need to be able to text her! She is 12. I appreciate any help.
This is an iPhone 4, with Sprint. We have 3 other iPhones, an iPod 4 and an iPad 2 on the same Apple ID account. We don't use the Cloud storage but I think the iCloud on the phone was turned on for a few things like Calendar.
Thank you in advance.Support profile is here:
https://daw.apple.com/cgi-bin/WebObjects/DSAuthWeb.woa/wa/classicLogin?appIdKey= 58ef9db8ff4d201409e7270a68e4408ae1678e1618204c476572a1b5e5fb3518&path&language=U S-EN
She would have had to register the phone using her Apple ID/password.
Changing her Apple ID password is the only other way to fix this if you don't have access to the phone.
You can also "try" calling AppleCare.
Maybe you are looking for
-
Connect to open ldap server using ODI
Hello, I need to use openldap as dataserver in ODI. But I'm not sure how to provide valid connection string. My test ldap server: - host: 172.18.0.106 - port: 389 - base dn: dc=example,dc=com And (optionally), root access (simple authentication): - B
-
I havent backed up my computer in almost 2 years due to a complication with the Time Machine (TM) But now it is fixed and it spends hours on "Cleaning old backups" And when it comes to backing up computers I am always scared to fix it blindly because
-
Not allowed Special characters
Hi Gurus, iam getting an error while activating the DSO request The error is u201CValue 'E Byron Car Realignment' (hex. '450020004200790072006F006E002000430061007200200052') of characteristic ZCOITEMTX contains invalid charactersu201D I donu2019t un
-
HT3702 I want to make a purchase
Hi I am trying to buy credit in one application and it's not working
-
Why is Firefox 5 unresponsive and locking up my Mac ?
Firefox 4 was awful, but Firefox 5 isn't much better. I have had to force quit Firefox 5 several times. It is also very slow and at times unresponsive. It slows down my whole Mac Book Pro, and makes other Apps unresponsive at the same time. I never h