"this." inside as2 classes
Can any one say, if i should use "this." inside my classes to
refer class
variables and methods? What is its advantage and
disadvantage? Does this
help compiler/flash player in any way.
please provide some useful links which explain more.
Cheers,
Sajeev
when it's appropriate you can use "this". so, if you've just
created a movieclip and you're defining a mouse handler for it,
it's appropriate to use this within the handler's scope.
but to refer to a class member, i use a private variable in
the constructor function to use throughout the class so i don't
have scope issues outside the constructor function.
Similar Messages
-
How to access var in outter class inside inner class
I've problem with this, how to access var number1 and number2 at outter class inside inner class? what statement do i have to use to access it ? i tried with " int number1 = Kalkulator1.this.number1; " but there no value at class option var y when the program was running...
import java.io.*;
public class Kalkulator1{
int number1,number2,x;
/* The short way to create instance object for input console*/
private static BufferedReader stdin =
new BufferedReader( new InputStreamReader( System.in ) );
public static void main(String[] args)throws IOException {
System.out.println("---------------------------------------");
System.out.println("Kalkulator Sayur by Cumi ");
System.out.println("---------------------------------------");
System.out.println("Tentukan jenis operasi bilangan [0-4] ");
System.out.println(" 1. Penjumlahan ");
System.out.println(" 2. Pengurangan ");
System.out.println(" 3. Perkalian ");
System.out.println(" 4. Pembagian ");
System.out.println("---------------------------------------");
System.out.print(" Masukan jenis operasi : ");
String ops = stdin.readLine();
int numberops = Integer.parseInt( ops );
System.out.print("Masukan Bilangan ke-1 : ");
String input1 = stdin.readLine();
int number1 = Integer.parseInt( input1 );
System.out.print("Masukan Bilangan ke-2 : ");
String input2 = stdin.readLine();
int number2 = Integer.parseInt( input2 );
Kalkulator1 op = new Kalkulator1();
Kalkulator1.option b = op.new option();
b.pilihan(numberops);
System.out.println("Bilangan yang dimasukkan adalah = " + number1 +" dan "+ number2 );
class option{
int x,y;
int number1 = Kalkulator1.this.number1;
int number2 = Kalkulator1.this.number2;
void pilihan(int x) {
if (x == 1)
{System.out.println("Operasi yang digunakan adalah Penjumlahan");
int y = (number1+number2);
System.out.println("Hasil dari operasi adalah = " + y);}
else
{if (x == 2) {System.out.println("Operasi yang digunakan adalah Pengurangan");
int y = (number1-number2);
System.out.println("Hasil dari operasi adalah = " + y);}
else
{if (x == 3) {System.out.println("Operasi yang digunakan adalah Perkalian");
int y = (number1*number2);
System.out.println("Hasil dari operasi adalah = " + y);}
else
{if (x == 4) {System.out.println("Operasi yang digunakan adalah Pembagian ");
int y = (number1/number2);
System.out.println("Hasil dari operasi adalah =" + y);}
else {System.out.println( "Operasi yang digunakan adalah Pembagian ");
}Delete the variables number1 and number2 from your inner class. Your inner class can access the variables in the outer class directly. Unless you need the inner and outer class variables to hold different values then you can give them different names.
In future place code tags around your code to make it retain formatting. Highlight code and click code button. -
I don't have a problem as much as just a lack of
understanding:
Question: Will I run into any problems using onEnterFrame
inside a class? I know that onEnterFrame events can overwrite each
other if they are written dynamically, but I'm not sure how this
effects classes...
Also, onEnterFrame is an event of the movie clip class right?
...does that even matter...? What happens if I declare an
onEnterFrame event inside a method inside my class: will it even
work? will it effect the movie clip from which the class.method is
being called?
Sigh... Hopefully you get the idea of what I'm having trouble
grasping. Please explain any concepts you think I appear to be
missing. I'm new to classes - thanks for your help.>>Question: Will I run into any problems using
onEnterFrame inside a class?
No.
>>Also, onEnterFrame is an event of the movie clip
class right? ...does that even matter...?
No. Here is a brief explanation how it works.
First of all, a class is a custom object. Don't think of a
class as a bunch of code, it's a custom object with its own
properties and methods. So when you say: "What happens if I declare
an onEnterFrame event inside a method inside my class: will it even
work?" you are thinking: "there is no timeline". Yes, there is.
When you declare:
private var my_mc:MovieClip;
you are saving the functionality of the MovieClip Class in
my_mc. Therefore, my_mc will have a timeline and all other
properties and methods of the MovieClip Class. (By comparison:
usually you don't need all the functionality of the MovieClip
Class, so AS3 offers us the Sprite Class which is a basic
implementation of a movieclip and that saves overhead).
In a method you can use:
private function mover(target:MovieClip):Void{
target.onEnterFrame=function():Void{
this._x+=2;
passing the my_mc to function mover as a parameter. If at
some time you want to stop the onEnterFrame you delete it just as
you would using it in code on the timeline.
Again. The most important thing to understand is that a class
is not a bunch of code, it's a (custom) object with its own
properties and methods. -
Foreground color change from inside a class
Hey,
For a project I'm working on, I wrote a class that extends awt.Label. In this new class, I had to override the paramString() method to return what I wanted it to. This all works great. What I was wondering, is whether or not it was possible to change the foreGround color of the label from inside the class decleration. I was thinking maybe whenever the paramString() method was called. Any help would be appreciated.
Thanks,
JarrodGday,
I you use the mothed setForeground(Color c) it should set the foreground colour (color for you Americans) to what you would like.
see for more info
http://java.sun.com/j2se/1.3/docs/api/java/awt/Component.html#setForeground(java.awt.Color)
or
http://java.sun.com/j2se/1.4/docs/api/java/awt/Component.html#setForeground(java.awt.Color)
if you have jdk1.4
You dont need to make this method in your class just call it when you want. ie
setForground(Color.RED);
or
Color c = new Color(255, 0, 0);
setForeground(c);
Good luck,
Jack 573 -
How to call a function inside a class?
Hello, i am trying to fire a function onPress .. this
function is inside a class.
In this function i refer to another function inside the calss
to call a Tween. It never arrives in the second function.
I tried to make an example.
In the fla file i have:
var test:makeMovie = new makeMovie(this);
You will see a red squere and you can press on it. It should
run the tween class. Am i using the delegate class wrong?I always have to use test movie and trace a couple of times
each time I start to use Delegate.
It wraps function.apply I think, which I tend to use more
often.
try using:
Container.onPress = Delegate.create(this,setAlpha);
and then just
setTween()
inside your setAlpha....
That's conceptually how I think I would try it above if I was
doing something similar.
I'm not sure it would have the desired effect even if the
delegate was executed as you have it coded. Unless you want
setTween's execution scope to be the Container clip in which case
you might need to do what kglad said and change the Container
reference to 'this'.
The way you have it at the moment inside setAlpha the
Delegate.create is simply creating a function...and not excuting
it.
its like : function something(){trace('what')}
and not like : something();
Below is some quick code that helps show how things work.
Notice that I assigned the delegate function to mainFunc....so that
along with the last example might provide a clue. Just paste it on
a frame and take a look at what's happening. -
Shouldn't all methods pertaining to an object be defined inside that class?
I am trying to understand if I am missing something basic java-wise (I come from other oop environments) or am I facing an ide-style/problem, or maybe I HAVE NO problem.
The way I always had it, was to place all code (functions/procedures/properties) INSIDE the class that it was meant for. But jDev does not do this, and again maybe its Java I'm up against, but then maybe not. Here is a clear example of what I mean. (All SWING.)
On a new jFrame, define a container, and inside the container a jComboBox and a jtextfield. The objective is to ADD ITEMS to the combobox, then upon a trigger event, specifically item_changed (when the user chooses an option from the item list), display a message to the jTextfield. (This differs from the tutorial sample requiring a button.) The purpose of jPanel is to tie the combobox and textfield via delegation. Ultimately we want an extended jPanel that I can (drag and drop) import into any project and drop it onto any jframe.
We have two distinct custom-operations/extensions, 1) is to add_items, and 2) is to talk to another object to display text. First the add_items; ideally I should be able to (if I want to) add_items inside an extended jCombobox and reuse it. Why put the add_items on the jFrame??? jFrame has NOTHING to do here with my little extended-jPanel. I SHOULD be able to choose if to put it into the extended jPanel, as well. (Since this jPanel is built with the purpose of serving a micro-framework for the two objects it contains.)
Similarly with 2, display the text message. I should be able to define the trigger event message to send upon item_change inside the jComboBox class. jPanel would then receive the message via delegation and take care of sending the message to jTextfield, also preferably to an extended jTextfield. But AT THE LEAST, all methods/properties should be within the extended jPanel. (Again, which I want to simply import and reuse.) Why does the ide put this code at the jFrame level? (By the way, if I copy/paste this jPanel, the ide does NOT add the appropriate imports (for the events) to the target jFrame, and neither does it copy the methods that are triggered. This seems like a bug, but I couldn't care less if I can accomplish what I described here.)
Having said all this I am ready (and hoping) for an answer that I am missing something basic in Java.
Thank you all
-NatIn fact, you don't even need the jbInit() method if you're just using the component as a bean in other components.Cool.
For the component to display properly in the UI editor, it should be a descendent of Component.ok. Does this mean that you can have a component (if not extending jComponent) that does not display properly in the ui editor, and still be properly maintained by the ide? That would be very nice, as long as the ui editor displays a mnemonic/icon instead of that component. I don't [always] NEED the
cutsy picture displayed, but I DO need to know that a component so-and-so is located 'here'.
AS a matter of a fact, I would love to have a pseudo-ui mode in jDev where you can build/maintain a frame with panels and icons representing components, where you can visualize the hierarchy, change the layout via drag-drop of the icons, and drill down. I have a gut feeling that people would use this mode more than the full ui mode we have now. Also, performance wise, jDev would be happier. This view allows one to get a clear wide-angle 'picture' of the layout (and delegation paths) of the classes. Coupled with 'drill down' to allow inserting/maintaining components within others, you have a winner!
Wadda you think? Am I nuts or something?
Come to think of it, it should not be tough for the jDev team to do this, since jDev is already doing something much more complex in the ui_editor. Instead of drawing pictures, when a bean is dropped, simply leave the icon as-is. 9.0.3??<g>
WE developers know that sometimes you can add tremendous functionality (especially from a marketing point of view) to a system, with minimal amount of work.
Sheesh, I forgot what put soapbox mode 'on'. I still would like to know how jDev would currently treat a bean that is not a sub-classed jComponent.
Thanks
-Nat -
Calling a private function when inside another class?
Can't help it but im curious how classes seem to be able to
call private functions inside other classes. I'm mainly thinking
about the addEventListener() here. When adding a listening function
to a class, that function can be private, and yet it seems to be
called magically somehow. Or maybe its all internal? I dunno.
Anyone? :DHi Kenchu1,
You can grab a copy of the open source API here:
http://www.baynewmedia.com/download/BNMAPI10.zip
(feel free to drop by
the main site for documentation as well :) ). The main class
is the
Events class, "broadcast" method. This method broadcasts
events in a
decoupled fashion, meaning that listeners can listen to
messages that
aren't bound to a specific sender. The AS3 version works in
much the
same way except that I still haven't fully fleshed out the
cross-SWF
communication that this version can do (broadcast across all
movies on
the same computer using LocalConnection).
Basically, the broadcaster works like this:
1. Add event listener and bind to function A (called from
within the
class so the reference is available)
2. Event listener pushes this into the listener array. It was
provided
by the class so the reference is valid and is now a part of
the events
class as well.
3. Broadcast runs through all associated events when it comes
time to
broadcast and calls the function by using the array
reference:
this.listeners[message].call(classInstance,someParameter);
In other words, the class that adds the listener "allows"
the event
broadcaster to use the reference because it passes it out.
You can do
the same thing by calling:
someOtherclass.functionRef=this.privateFunction
someOtherClass is the class that will store the private
reference,
functionRef is some variable to hold the reference, and
privateFunction
is the private function. Then, in someOtherClass, you can
call:
this.fuctionRef(someParameter);
Hope this helps.
Patrick
Kenchu1 wrote:
> Patrick B,
> exactly! Something like that is what im looking for. I
have my own rather
> simple system right now with listeners and classes
calling these, but since i
> dont know how to call a private function, i had to make
all the listening
> classes functions public - something id rather avoid.
Exactly how did your
> event broadcasting system work? Oh, and we're talking
AS3 btw.
>
> How do i call a function via a reference? (to the
function? To what?)
>
http://www.baynewmedia.com
Faster, easier, better...ActionScript development taken to
new heights.
Download the BNMAPI today. You'll wonder how you ever did
without it!
Available for ActionScript 2.0/3.0. -
Native methods inside C++ class
Hey all,
Tried posting this already but it didn't appear in the forums. So apologies if this appears twice on same forum :o)
Want to wrap my native methods inside a C++ class but get UnsatisfiedLinkerError when I do. Is it possible to do this? Do I have to change some method signatures or what?
I want something like :
public class A
native void doSomething();
class B
public:
JNIEXPORT void JNI Java_A_doSomething() { ... } /* or whatever */
It works ok outside of a C++ class but I'd prefer to contain my methods inside a class. Any help?
Cheers,
ConorJava needs to find your functions in the DLL or SO. But the names are "mangled" if you declare the function inside a class - even declaring the function "static" does not help. For instance, using the Microsoft C++ compiler:
class B
public:
static JNIEXPORT void JNI Java_A_doSomething() { ... }
};the name is mangled to ?Java_A_doSomething@B@@SAXXZ
But Java tries to locate the entry _Java_A_doSomething@0 in the DLL.
You can write the global functions as:
JNIEXPORT void JNI Java_A_doSomething() {
B::doSomething();
}and implement your functions in the class B. The advantage of this approach is that you can write all bookkeeping work of converting Java data to C++ data in the global function, and leave the real work to the function declared in the C++ class. -
To get all the objects that are used inside the class
Hi All,
All i wanna know is to get all the objects that are used inside the class.
Ex :
Class A{
Emp e;
public add(Dept d){
e.deptid = d.deptId;
in this class i have two objects, one Emp obj and another Dept object.
I wanna get the details abt this class Emp and Dept by simply parsing the file and by not loading this class in JVM.
Could any pls hel me out.??
thx.I wanna get the details abt this class Emp and Dept
by simply parsing the file and by not loading this
class in JVM.Your problem statement is vague and the constraint is IMO hypothetical. -
Cant do setColor(Color.BLACK); to a graphic object inside a class
i have a graphic object inside a class:
JPanel panel = new JPanel();
Graphic lienzo = areadibujo.getGraphic();
and then i cant do this:
lienzo.setColor(Color.BLACK);
netbeans error:
<identifier> expected
i just can do that inside a method from the class...HI i found the problem.
The problem is that when i create the graphic object i do this:
Graphics lienzo = areadibujo.getGraphics();
areadibujo.getGraphics(); returns null so when i try to do something like lienzo.drawline(1,1,200,200); it just says nullpointer error, i guess at the time i create graphic object the panel "areadibujo" is not still created because the frame doesnt still shows, i can correct this by copying Graphics lienzo = areadibujo.getGraphics(); inside a actionperfmoded or other event method , but i dont wanna do that, where does the panel object already is created in constructor?.... i dont know if i explain my self well or how can i force areadibujo.getGraphics() to return something... -
What is the purpose of Static methods inside a class?
Hi,
What is the purpose of Static methods inside a class?
I want the answers apart from "A static method does not require instance of class(to access) and it can directly be accessed by the class name itself"
My question is what is the exact purpose of a static method ?
Unlike attributes, a separate copy of instance attributes will be created for each instance of a class where as only one copy of static attributes will be created for all instances.
Will a separate copy of instance method be created for each instance of a class and only one copy of static methods be create?
Points will be rewarded for all helpful answers.Hi Sharma,
Static methods is used to access statics attributes of a class. We use static attributes when we want to share the same attribute with all instances of a class, in this case if you chage this attribute through the instance A this change will change will be reflected in instance B, C........etc.
I think that your question is correct -> a separate copy of instance method will be created for each instance of a class and only one copy of static methods be create ?
"A static method does not require instance of class(to access) and it can directly be accessed by the class name itself"
Static Method: call method class=>method.
Instance Method: call method instance->method.
Take a look at this wiki pages.
[https://wiki.sdn.sap.com/wiki/x/o5k]
[https://wiki.sdn.sap.com/wiki/x/ZtM]
Best regards.
Marcelo Ramos -
Why do I get this MyClass$1.class
Hello,
I have the following simple class:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class HelloJava2
extends JComponent implements MouseMotionListener {
// Coordinates for the message
int messageX = 125, messageY = 95;
String theMessage;
public HelloJava2(String message) {
theMessage = message;
addMouseMotionListener(this);
public void paintComponent(Graphics g) {
g.drawString(theMessage, messageX, messageY);
public void mouseDragged(MouseEvent e) {
// Save the mouse coordinates and paint the message.
messageX = e.getX( );
messageY = e.getY( );
repaint( );
public void mouseMoved(MouseEvent e) {}
public static void main(String[] args) {
JFrame f = new JFrame("HelloJava2");
// Make the application exit when the window is closed.
f.addWindowListener(new WindowAdapter( ) {
public void windowClosing(WindowEvent we) { System.exit(0); }
f.setSize(300, 300);
f.getContentPane( ).add(new HelloJava2("Hello, Java!"));
f.setVisible(true);
I don't understand what the file called HelloJava2$1.class comes from. There is only one class definition in the source so where does this xx$1.class file comes from?
Thanks in advance,
Balteo.If you wrote it like this:
f.addWindowListener(new MyWindowCloser());
class MyWindowCloser extends WindowAdapter {
public void windowClosing(WindowEvent we) {
System.exit(0);
}then it would be more obvious where the file came from.
These are basicly the same except one can be referenced. -
How to define an itab based from a structure inside a class
Hello Experts,
How can I define an internal table based from a structure that
is declared inside a class?I want to define it in the START-OF-SELECTION event.
I'll create a scenario below:
* CLASS lcl_main DEFINITION
CLASS lcl_main DEFINITION ABSTRACT.
PUBLIC SECTION.
TYPES: BEGIN OF t_vbak,
vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
ernam TYPE vbak-ernam,
auart TYPE vbak-auart,
kunnr TYPE vbak-kunnr,
vkgrp TYPE vbak-vkgrp,
END OF t_vbak.
ENDCLASS. "lcl_main DEFINITION
START-OF-SELECTION.
*Here i want to define an internal table based from the structure T_VBAK.
Hope you could help me out here guys. Thank you and take care!.
-
Calling a Function Pool inside a Class
Hi,
I want to call a Function Pool inside a Class Method. I am getting an Error that 'Report or Program Statement already exists' when I call the function pool in the method. can anybody help me on how to call a Function Pool inside a class method.Hello Krish
Based on your error description I assume that you have tried to "insert" the function pool program (e.g. function group ZFUNC -> SAPLZFUNC) into your class.
You cannot do that. The explanation for the error message is a following:
- The class contains already a program statement (CLASS-POOL). If there is somewhere in the class an additional program statement (e.g. FUNCTION-POOL) you will get the error.
In addition, you cannot "call" a function pool. Instead you can always call the function modules of your function group.
Regards
Uwe -
CS4 no longer recognizing AS2 classes
Issue: I designed a site in CS4 using AS2 and external AS2 classes. Everything worked fine until about a week ago. Now when I go back and try to edit those files, the classes are no longer loaded and the site breaks.
I haven't edited any of the code, just graphics.
I even tested other files that use external classes and those break now as well. (I keep daily backups of my progress. Published two weeks ago: fine; publish the same file today: broken.)
I went into the AS2.0 Preferences and they're set the way they always have been:
$(UserConfig)/Classes
$(LocalData)/Classes
Since publishing those working files, the only thing I've been doing is a bunch of AS3 tutorials on Lynda. I haven't edited any AS libraries or settings or preferences, so I can't figure out what's going on.
Has Flash gotten confused? How can I get these reconnected? Thanks.Ok, so that was the issue. I had connected to the FLA to the AS file, but not the AS file to the FLA.
I had assumed that the general preferences, ($(UserConfig)/Classes, and $(LocalData)/Classes) were setting up the default connection to the Classes folder in my dev environment. That's why I had the folder titled "Classes" with a captial letter, and didn't link things all the way in either the FLA or the AS files.
I changed Classes to lowercase, connected it in the FLA, ("classes.com.skin.Scrubber"), then matched the same in the first line of Scrubber.as (class classes.com.skin.Scrubber extends MovieClip) and got things linked up.
Thanks so much!
I just wish I knew why things were working fine until now.
Maybe you are looking for
-
How can I hide hidden files again?
Hi I just bought a new macbook pro with maverick 10.9.3 I believe and made my hidden files viewable to extract certain data. But now I want to hide the files again how do I go about doing that? thanks!
-
Fix Invalid XML character (Unicode: 0x1c) before xml data parsing
How to fix the error :- "An invalid XML character (Unicode: 0x1c) was found in the element content of the document." This error message is generated before parsing of xml data. So how to filter the unwanted characters like 0x1c during XML file genera
-
when i clink a given link in google search than that webpage open in another window. How i can open that page in the same tabe ?
-
10.5.8 update_'You cannot install Mac OS X Update on this volume.'
You cannot install Mac OS X Update on this volume. This volume does not meet the requirements for this update. This is the message I get when I click on the hard drive I wan to install it on, I have two hard drives, neither want to work with it. the
-
If you've upgraded to OS 10.2.1.x on your BB10 device you can now install any free Android app directly to your BB10 smartphone directly without any special converting and without the need to connect to your PC. This opens up BB10 to the thousands o