ActionScript 1/2 :: Handling Cross-class Variable Changes
Jul 8, 2009
I recently decided to learn Actionscript. I'm taking the plunge, and jumping straight into making a fighter game with a little aid from some tutorials on a few parts of it. It's going fine, though I'm sure my form is none to great. The issue I've run into is I'm not sure how to make one class change a variable in another. The specific case is that I've got a p1 and a p2 class, and I want to be able to increase their delay when they get hit. I'd also like being able to do stun attacks, and set up a dynamically scrolling background to give the illusion of a wider playing field. I've got all the logic worked out, I just need to know how I tell the p1 class to alter a variable in p2, and vice versa.I'm using AS2 because the tutorials were designed for it. If switching to AS3 is necessary, I'll learn what I have to, but I would prefer to stay with 2 if it works.
View 4 Replies
Similar Posts:
Aug 19, 2010
Is there any cross-platform-safe method for dealing with keyboard shortcuts in Flash? For example, on my Mac, pressing ctrl+f results in a KeyboardEvent where the keyCode is 6, but on Windows, the keyCode is 70.
View 1 Replies
Jan 6, 2010
The following bit of javascript writes and retrieves a cookie which counts a users visits to the page. Then using swfobject it both embeds main_banner.swf and passes the cookie value "visits" to it via flashvars. The trouble is in the actionscript below; the vallue has been passed (this is certain, because the .swf shows up rather than the alternative content)- but the .swf is stuck on the first frame rather than processing the cookie and sending the user to the appropriate frame label.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html [code].....
View 6 Replies
Aug 19, 2011
I've noticed BlazeDS has certain things it does not support and it is often difficult to find this out. Ex: polymorphism is not.One must create methods with different names as methods with the same name with different parameters create a conflict.I'm trying to find out if BlazeDS does not support Java static and non-static inner classes.
public class UserDTO {
private String name;
private AddressDTO adddress;
private PhoneDTO phone;
[code]...
The example code above will compile and the getUser method will work. A call to the updateUser or updatePhone methods on the other hand results in a BlazeDS error. Is there a special way to use inner classes in Flex or are inner classes not supported?
Here is an example of the error messages produced:
[BlazeDS]Cannot create class of type 'com.test.dto.UserDTO.PhoneDTO'.
flex.messaging.MessageException: Cannot create class of type 'com.test.dto.UserDTO.PhoneDTO'. Type 'com.test.dto.UserDTO.PhoneDTO' not found.
Example Flex code:
var thisPhone:PhoneDTO = new PhoneDTO();
thisPhone.phoneNumber = "8885551212";
updateTagsResult.token = userService.updatePhone(thisPhone);
View 2 Replies
Mar 29, 2010
I am using bitmapData and bitmap classes to render a mouse cursor on the display screen. The bitmapData consists of an area whose colors should be inverted according to the background color. This is a very basic thing which could be observed with text cursor(the vertical line with two small horizontals on top and bottom), when moved over the text area. want to be able to do the same with the pixels in my bitmapData, is there a way to find out the background color effectively and invert the color values? In this process i will be redrawing the whole pixels, is there any other efficient way to do that ?
View 1 Replies
Aug 4, 2011
I have created a simple mxml file with code as follows:
<s:application..........>
<s:BorderContainer>
<s:SkinnableContainer id="firstRow"/>
<s:SkinnableContainer id="secondRow"/>
<s:SkinnableContainer id="thirdRow"/>
</s:BorderContainer>
</s:application>
Now I want to apply different font size, font color and font type and background color on each row i.e each of the three skinnableContainers.Currently I have defined 3 different skin classes for each of row but I think this is a bad programing. I should create a single skin class for outermost container i.e BorderContainer and any how provide different fonts and background color to all the 3 child containers through that skin class. So, is it possible that I can create single skin class that can provide different decorations to each of the child container.
View 1 Replies
Mar 29, 2011
According to Cairngorm architecture, we always have a fault handler in every command class for each service.How we can create a single Class for handling Fault handler event for all the services.
View 2 Replies
Nov 5, 2010
My swf works fine when previewed locally but because of flash cross domain issues (link below) doesnt work live. [URL] Ive used a 'crossbrowser.php file to .load in xml but am not having success with the sendAndLoad command. [URL]
View 3 Replies
Oct 12, 2010
i have a movie clip which is exported for ActionScript , i want to get a variable from the document class into the movie clip class i tried this but there was an error !!
ActionScript Code:
var main:Main=new Main();
main.txtScore.text="hello";
View 1 Replies
Feb 19, 2010
I realize this is kind of an odd issue, but I am wondering if there's any way to get Flash to allow me to access a class's static functions using a class variable that points to the class. Example:I create a class called FooClass that has a static function named fooI then create a variable of type Class that points to it
Code:
var class:Class = Class(getDefinitionByName("FooClass"));
However, when I try to call foo() using the variable, it errors saying the function
[code].....
View 6 Replies
Dec 28, 2009
I'm trying to create a class which will create a tween for several different instances of an object. I am creating the instances in the Document Class. The trick is, I would like to specify how long each tween will take.
Here's what I have so far:
DOCUMENT CLASS
ActionScript Code:
package {
import flash.display.MovieClip;
import mcCloud;
[Code].....
As you can see, I have a variable "myTime" which syncs the timer and the tween. This causes to tween to repeat and the clouds to continually scroll across the stage. How can I determine the var myTime at the time I create each instance of the Movie Clip mcCloud?
View 6 Replies
Aug 31, 2011
When I declare a class variable
private var myVar:MyClass = new MyClass();
It creates a new instance of that class that will trace as [Object MyClass].
However, as soon as I assign it to something
myVar = thisOtherVar;
It will now trace as [Object thisOtherVar].
I need to get it back to where it's just an "empty" blank class instance, if that makes any sense at all.
View 14 Replies
Mar 14, 2011
I've only been programming in as3 for a couple months, and so far I've written several compositional classes that take MovieClips as inputs to handle behaviors and interactions in a simple game I'm creating. One problem I keep coming upon is that I'd love to access the custom variables I define within one class from another class. In the game I'm creating, Main.as is my document class, from which I invoke a class called 'Level1.as' which invokes all the other classes I've written.Below I've pasted my class 'DieLikeThePhishes'. For example, I would love to know the syntax for accessing the boolean variable 'phish1BeenHit' (line 31) from another class. I've tried the dot syntax you would use to access a MovieClip inside another MovieClip and it doesn't seem to be working for me.[code]
View 1 Replies
Mar 14, 2011
I've only been programming in as3 for a couple months, and so far I've written several compositional classes that take MovieClips as inputs to handle behaviors and interactions in a simple game I'm creating. One problem I keep coming upon is that I'd love to access the custom variables I define within one class from another class. In the game I'm creating, Main.as is my document class, from which I invoke a class called 'Level1.as' which invokes all the other classes I've written.Below I've pasted my class 'DieLikeThePhishes'. For example, I would love to know the syntax for accessing the boolean variable 'phish1BeenHit' (line 31) from another class. I've tried the dot syntax you would use to access a MovieClip inside another MovieClip and it doesn't seem to be working for me
package jab.enemy
{
import flash.display.MovieClip;
[code].....
View 1 Replies
Mar 11, 2011
I need to increment an integer variable in a function within the document class upon transpiring event in another class. I can't seem to figure out how to call the function and reference the variable.
View 2 Replies
Apr 25, 2011
How do I listen from the main class to a sub class for a variable change?
package {
import flash.events.*
public class DataBase extends MovieClip {
[Code].....
This is what I have so far for the sub class but I can't seem to figure out how to listen to this variable change from Main() or even if I am dispatching the event properly.
View 2 Replies
Mar 11, 2009
I have an array in my doc class that I'd like to access from an external class. Can you do this and if so what's the syntax?
View 6 Replies
Sep 7, 2010
I have two document classes. One is Main.as the other is Step2.as. I want to declare a public variable in Main.as then need to give it a value from Step2.as. That value will later be used in my next Document class Step3.as How would I write the code that gives the value in my Step2.as and then how would I write the code that retrieves the value in my Step3.as?
Note I can't import my Step2/ or Step3 document class into my Main.as.
View 2 Replies
Jul 21, 2010
would it be possible to access a variable name containing a class from the class itself?
Example:
Code:
var __NAME__ = new TestClass();
package com.Test
{
[Code]...
View 14 Replies
May 8, 2009
Having just made the jump from Actionscript 2 to 3, I'm having problems.Is it possible (I hope so) to use a variable when creating a class?I have a movieclip 'exclam' in the Library, and want to programatically add it to the scene: I can use the code:var asset:exclam = new exclam();to do this. However, if I have a variable 'textvar' containing "exclam", I'd like to use code like:var asset:textvar = new textvar();Of course, it doesn't work, since it thinks 'textvar' is the name of the movieclip I'm trying to use. Hopefully it's just a matter of syntax.
View 4 Replies
Feb 16, 2012
I am developing flash game.
first class:
public class Game{
public var age;
[code].....
View 1 Replies
Sep 28, 2011
ActionScript Code:
private function xmlLoaded(e:Event):void{
xml = new XML(e.target.data);
for (var i:int = 0; i < xml.item.length(); i++) {
var btn:Button = new Button(xml.item[i].label, xml.item[i].@id, xml.@colorOver, xml.@colorOut);
btn.y = Math.floor(i * btn.height);
[Code] .....
Simple, inside my Button class I gave a value to "id" how can i retrieve it from the event? Tried lots of stuff, just don't know how:
trace(e.target.id);
Something like that.
View 3 Replies
Sep 9, 2007
I have just created a class 'ClassA' that loads an XML file.Within that class I have a public function that navigates through the XML and populates arrays with the XML content.
I am now creating another class, which will be called 'ClassB' which I plan to extend 'ClassA'.
>From 'ClassB' I would like to reference the array variable (which is not in the constructor) to re-use in the 'ClassB' class. I have tried tons of different ways all of which I get undefined.
View 2 Replies
Mar 3, 2005
i'm having an issue fitting setInterval() methods into an AS2 class--basically, since setInterval works by calling a function at a set interval, and it returns an object reference, like this:
Code:
public function loadSplash():Void {
var id=setInterval(loadSplashMC,1000);
var sM:Object=new Object();
Mouse.addListener(sM);
[code]....
the problem is that i can't set a class variable to id--i tried defining it as a generic object, like this:
public var id:Object;
but it didn't work...i'm not used to working with setInterval, so maybe i'm just not using it right--perhaps i should put it all into one function?
View 4 Replies
Jan 7, 2010
Any way that I could get a variable definition straight from a class (or some sort) without having to create an object and read it from the object. Basically I need to know a whether an object will have a specific true or a false variable definition but I don't need to create the object right away for anything else. It seems a bit of extra processing to create an object I may not use for sometime but just needed to know a true/false early on. I can give it the name of the class just hoping to bypass the object creation and hope garbage deletion will take care of it.
View 1 Replies
Apr 11, 2010
How to access a local variable from another class? I have this powerup class that changes the speed value of the enemy in enemy class(it's a game). For instance, if player hits the powerup it changes the local variable 'speed's value inside enemy class.
View 3 Replies
May 7, 2009
I am calling a function in one class from another (primary) class. That works with a straight function call.However, the function I am calling loads an XML file and, upon load completion, calls a handler function.My problem is that all data in the handler function disappears when the function terminates so I cannot access the result from the primary class.
View 4 Replies
Jun 9, 2009
I've created 2 public variables in my Document Class...
public var _wall1:Wall=new Wall();public var _wall2:Wall=new Wall();I've then added them to the stage and given them relevant instance names...
stage.addChild(_wall1);_wall1.x=32; _wall1.y=510;_wall1.name = "wall1";I then want to use these variables in another Class (Ball.as). They need to be accessed in a function within the Ball Class constructor.
function bubble(event:Event):void{if(this.hitTestObject(_wall1)){ this.x += 1;}else if(this.hitTestObject(_wall2)) { this.x -= 1;}However, the following Error message keeps appearing...
1120: Access of undefined property _wall1.1120: Access of undefined property _wall2.Any pointers? Do I need to import something into the Ball Class to point to the _wall# public variables in the Document Class?
View 1 Replies
Dec 22, 2011
I am Created One Animation in Action Script 2.0, in that I am Using Global Variables.Now I Create that animation in Action Script 3.0. But the Global Variable was shows Error.Any Passible for Using the Gloabl variable in AS3 Without Class.
View 1 Replies
Dec 9, 2010
I have a class with a var textFieldObjets:Textfield in my class environment. What I'd like to do, is access this var from another class and change the text. I tried things like
environment.textFieldObjets.text = ".....";
Got error 1119, Access of a possible undefined property textFieldObjets trough a reference with static type Class.
I can't even access my environment class...
View 2 Replies