Trying To Animate MC On Stage Using Tweener From Within A Custom Class
Hi,
I'm trying to animate a movieclip on stage using a custom class that uses Tweener. I'm not getting error messages... it just not animating. I've posted the class below... any ideas?
Code: package { import flash.display.*; import flash.events.*; import fl.transitions.Tween; import fl.transitions.easing.*; import fl.motion.easing.*; import fl.transitions.TweenEvent; import caurina.transitions.*; import ButtonSetup;
public class SceneNavigation extends MovieClip {
private var yIn:Number = -820; private var yOut:Number = -750; private var widthIn:Number = 6473; private var heightIn:Number = 610; private var widthOut:Number = 5942; private var heightOut:Number = 560; private var zOutTime:Number = .3; private var zBlurTime:Number = .1; private var zUnblurDelay:Number = .45; private var moveSpeed:Number = .3; private var zInTime:Number = .75; private var posOut:Array = new Array(2442, 1452, 460, -530, -1520, -2521); private var posIn:Array = new Array(2652, 1514, 450, -617, -1713, -2783); private var posOutStart:Number = posOut[0]; private var posOutEnd:Number = posOut[1]; private var posInStart:Number = posIn[0]; private var posInEnd:Number = posIn[1]; public var btnClicked;
public function SceneNavigation() { this.width = widthIn; this.height = heightIn; this.x = posIn[0]; this.y = yIn; } public function whichWay() { posOutEnd = posOut[btnClicked]; posInEnd = posIn[btnClicked]; /*if (posOutEnd > posOutStart && btnClicked != 0) { posOutEnd = posOut[btnClicked]-50; }*/ nextPage(); } public function nextPage() { Tweener.addTween(this, {x:posOutStart, y:yOut, width:widthOut, height:heightOut, time:zOutTime, transition:"easeInQuad"}); Tweener.addTween(this.blurStrip, {delay:zOutTime, time:zBlurTime, alpha:1}); Tweener.addTween(this.blurStrip, {delay:zUnblurDelay, time:zBlurTime, alpha:0}); Tweener.addTween(this, {x:posOutEnd, time:moveSpeed, delay:zOutTime, transition:"easeOutQuad"}); Tweener.addTween(this, {x:posInEnd, y:yIn, width:widthIn, height:heightIn, time:zInTime, delay:(zOutTime*2), transition:"easeOutQuad"}); posInStart = posIn[btnClicked]; posOutStart = posOut[btnClicked]; trace(this);
} } } The nextPage() function is supposed to animate a movieclip on stage. I've traced all the variables and they're values are correct. I've tried using "this.parent" and that didn't work either. This works when used from the main timeline. I've tried using a simple Tweener animation from another class on different object and it works fine there as well... I can't figure out what is wrong with this setup. Any help would be greatly appreciated.
UPDATE:
I'm passing in a value for the btnClicked variable from another class... this could be what's causing the problem. When I call the nextPage() function from the constructor the object does animate. Still not sure what's wrong.
KirupaForum > Flash > ActionScript 3.0
Posted on: 10-10-2008, 12:21 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Animate Timeline With Tweener As 2.0
Hi there, in Lee's tutorial about advanced after effects and flash, he animates timeline of a mc with Tweener, but the code is in AS3.0 , does anyone know how can i do it in AS2.0 ?!?!?!
i have a mc with a flv video in it, like in Lees tutorial , and a invisible button that will trigger the onRollOver function... i tried this code:
Code:
btn2.onRollOver = function() {
DisplayShortcuts.init();
Tweener.addTween(expl, {_frame:7,time:0.3, transition:"easeinoutquad"});
};
but still doesn't work...
Tweener - Can I Make/use Custom Tweens?
Hi there,
I was wondeirng if anyone knew of a way to make your own tweens instead of using the built in ones (eg. easeOutQuad). I know I once saw someone that had some kind of graph thing you could use to generate code? Any one have any ideas
Thanks in advance
Tweener + Stage Resize
Hi,
I'm using Tweener and my objects are tweening to parameters that are readjusted upon stage resize. If an object is tweening, I'd like the the tween to update it's parameters when the stage resize function is called. I've tried:
(resize function)
Tweener.pauseAllTweens()
sw = stage.stageWidth;
Tweener.resumeAllTweens();
But this doesn't seem to work. I've read all the Tweener parameters and can't seem to find one that will accomplish what I'm trying to do.
P.S. I know I can insert another Tween inside the resize function and it will overide. It's difficult to explain but this technique won't work for me.
Any suggestions? Thanks in advance!
Tweener Class
Ok everyone and there mom says this class is so great but I'm pulling my hair out just to get it to import right. Maybe its not great and everyone else is on crack, or I'm missing something.
I imported caurina to my nav class which is imported to my main AS file.
I put this in:
Code:
import com.caurina.transitions.*;
as that is where i have the file located and I have my flash AS 3.0 set to look in that main folder for classes.
I then put this in:
Code:
private function moveBtn1():void {
Tweener.addTween(btn1_mc, {_alpha:100, time:1});
}
The result are these errors:
Code:
1046: Type was not found or was not a compile-time constant: TweenListObj.
1180: Call to a possibly undefined method PropertyInfoObj.
1180: Call to a possibly undefined method TweenListObj.
and BUNCHES more, its so gay, what do I do???
HELP!!
Tweener Class
I wanted a movieclip to appear and disappear after the push of a button. I tried:
on(release){
import caurina.transitions.Tweener;
Tweener.addTween(mymovieclip, {_alpha:100, time:2});
Tweener.addTween(mymovieclip, {_alpha:0, time:2});
}
On the other hand:
on (release){
import caurina.transitions.Tweener;
Tweener.addTween(mymovieclip, {_alpha:0, time:2});
}
and
on (release){
import caurina.transitions.Tweener;
Tweener.addTween(mymovieclip, {_alpha:100, time:2});
}
work fine.
How can I accomplish it?
Tweener And Timer Class
Hello.
This is my first attempt at using the tweener and timer classes for AS3. I'm trying to cycle through a stack of photos and I want it to tween to the next photo in the stack every second or so. As of the code below I have it working on mouse click but I would like it to tween each time the timer is triggered instead. I've tried several things but they all seem to be wrong. This seems like an obvious switch... any ideas?
Thanks!
[AS ]
import caurina.transitions.*;
var photoOriginX:Number = photo1.x;
var photoDestX:Number = photoOriginX - 200;
var speed:Number = .5;
var rotationRange:Number = 0;
var photoCount:Number = 5;
var easeType:String = "easeoutquad";
var myTimer:Timer = new Timer(2000,8);
myTimer.addEventListener(TimerEvent.TIMER, timerListener);
function timerListener (e:TimerEvent):void {
trace("Timer is Triggered");
}
myTimer.start();
function photoSlideOut (e:Event):void {
e.target.parent.setChildIndex(e.target, e.target.parent.numChildren - 1);
Tweener.addTween(e.target, {x: photoDestX, time: speed, transition: easeType, onCompletehotoSlideIn, onCompleteParams:[e.target]});
Tweener.addTween(e.target, {rotation: Math.floor(Math.random()*(rotationRange*2))-rotationRange, time: speed*2, transition: easeType});
}
function photoSlideIn (p:MovieClip) {
p.parent.setChildIndex(p, 1);
Tweener.addTween(p, {x: photoOriginX, time: speed, transition: easeType});
}
for(var i=1; i<=photoCount; i++) {
this["photo"+i].addEventListener(MouseEvent.MOUSE_DOWN, photoSlideOut);
this["photo"+i].rotation = Math.floor(Math.random()*(rotationRange*2))-rotationRange;
}
[/AS ]
AS3 - New Extendible Tweener Class
Hi all!
I had a few days off so i decided to make something useful. My idea was to make a tweener class but not yet another tweener class, i wanted to make this class extendible, since i've got lost between the great number of available tweenings class which everyone have a feature of his own, i wanted to make a tweener base class, and to show the usefulness of this extendibility i created a ChainedTweener class which inherits from the base class.
i'll be pleased if you check it out!
extendible Tweener class :
http://halfrobot.wordpress.com/2008/...tweener-class/
ChainedTweener class :
http://halfrobot.wordpress.com/2008/...tweener-class/
[F8] Problem With Using A Custom Class Inside A Custom Class
I'm getting this error:
Line 19: A function call on a non-function was attempted.
var a:Meter = new Meter(32,34,0x0000ff,0,0);
when I am trying to call a custom class (Meter) inside of another custom class, which I initialize in the main timeline. I can do this exact same line I copied above in the main timeline and it will work just fine, but not if it is used in the constructor of another custom class as I am trying to do. Any ideas on why this isn't working? Only thing I can come up with is that the class isn't imported at the time of the second class calling it but I've tried fixing that already.
New Tweener Class Help With Tests And Bug Report
Hi!!
I developed a new tweener class with nice special FX support!
See some demos on http://thelaborat.org
On the "Projects" topic of the sidebar click on Light Transition to see some tutorials and download the source!
Help me in the project page in order to find bugs and improve the class even more!
Thanxs!!!
Define Tweener In The Document Class
I have a movieclip on stage with instance name top_mc.
This is the code I want to apply to it:
Tweener.addTween(top_mc, {x:726, y:30, time:0.8, transition:"easeInOutCirc", delay:0.1});
Can't do it on stage! need to define it in the document class...
Can somewone give me the right code?
thanks
Tweener And Graphics Class Problem
I am having a problem using tweener and graphics class. I am trying to design a UI that, when clicked, scales up. I used the caurina tweener class, set the initial value of the graphic to .2 and then scale up to 1.0. The object does successfully scale up but it also MOVES. I didnt change the x or y position in the tween function but it seems to move downward A LOT. Anyone had this problem? The interesting thing is, if I draw the graphic visually using the rectangle tool, convert it to a movieclip and then add the same tween, it acts as it is supposed to. Code is posted below. Thanks in advance.
Code:
import caurina.transitions.*;
var rectangle1:MovieClip = new MovieClip();
var g:Graphics = rectangle1.graphics;
g.lineStyle(2, 0x95ca86, .5);
g.beginFill(0xe9f2d8, .5);
g.drawRoundRect(200,200,600,600, 25, 25);
g.endFill();
rectangle1.x = 12;
rectangle1.y = -175;
rectangle1.scaleY = .3;
addChild(rectangle1);
rectangle1.addEventListener(MouseEvent.CLICK, expand);
function expand(e:Event):void
{
Tweener.addTween(rectangle1, {scaleY: 1, time: 1});
}
Tweener Class Doesn´t Work
Hi,
I downloaded the Tweener classes 1 31 74 from the google code-site and tried the Tweener-Class tutorial, but I get the following error:
1046: Type was not found or was not a compile-time constant: TweenListObj.
Don´t mind. Found the solution....
viewtopic.php?f=29&t=15461
Animate A Custom Cursor?
Let's say you create a little gun movieclip to act as your custom cursor...
How would you make it shoot bullets when you click on anything?
Thanks for any and all attempts at guidance.
Arlen
Choppy Banner Transitions Using Tweener Class
Hi, I've made this banner that is apparently choppy. All the layout was done in Flash, and all of the animations are handled in the document class. It's basically an init function followed by a series of addTween's, each scene having it's own function, and then looping back.
I am using Tweener, and the client is saying it looks terribly choppy. I didn't know/couldn't tell on my machine, but upon looking at the screen of a slower comp, yeah it's terrible.
For the life of me I cannot figure out how to get the tweens to go smoother. That said there are some telltale clues on the trouble spots. I notice that any tweens related to only the alphas, that is the fades, tween fine with no problem. It's any movement of x or y that it goes all jittery. Also all of my fades are pretty much no longer than 1.5s. Each of my movements which involve some ginormous images (dimensionwise) are 3.5-5s long.
Other things of note:
Yes I am removing all tweens after each loop cycle. Firebug shows that there is no memory leak, but it does show some huge processing 75-90% occurring right when those movements (especially if there is also scaling) are happening - processing spikes.
The frame rate was at 31 to begin with, but is now ramped up to 60 which improved things slightly.
Here is a link to the banner in action:
http://tarkettna.johnsonite.com/
Yes, in retrospect, doing this in After Effects would probably have been the better tool to use even though some text rendering quality will be sacrificed, but this is so far into it, it would be nice to be able to fix what exists without having to start all over. Plus, I'd really like to move on to something else besides this bloody banner!
Build Menu Order With Tweener Class?
ActionScript Code:
function showsubMenu(x,y,thisArray,gotoArray){ var curr_item:MovieClip; var defaultX:Number = x; for (i=0; i<thisArray.length; i++) {curr_item = submenu_mc.attachMovie("menuItem", "menuItem"+i, i); curr_item._x = -250; curr_item._y = y + i * 40; ...... } for (i = 0; i < thisArray.length; i++) { curr_item = submenu_mc["menuItem"+i]; Tweener.addTween(curr_item, {base: slideIn } ); }}var slideIn : Object = { _x:20, time:1.5, delay: 2, transition: "linear"}
now all menuItem's slide in at ones. but i want to slide them in one after the other?
regards
Choppy Banner Transitions Using Tweener Class
Hi, I've made this banner that is apparently choppy. All the layout was done in Flash, and all of the animations are handled in the document class. It's basically an init function followed by a series of addTween's, each scene having it's own function, and then looping back.
I am using Tweener, and the client is saying it looks terribly choppy. I didn't know/couldn't tell on my machine, but upon looking at the screen of a slower comp, yeah it's terrible.
For the life of me I cannot figure out how to get the tweens to go smoother. That said there are some telltale clues on the trouble spots. I notice that any tweens related to only the alphas, that is the fades, tween fine with no problem. It's any movement of x or y that it goes all jittery. Also all of my fades are pretty much no longer than 1.5s. Each of my movements which involve some ginormous images (dimensionwise) are 3.5-5s long.
Other things of note:
Yes I am removing all tweens after each loop cycle. Firebug shows that there is no memory leak, but it does show some huge processing 75-90% occurring right when those movements (especially if there is also scaling) are happening - processing spikes.
The frame rate was at 31 to begin with, but is now ramped up to 60 which improved things slightly.
Here is a link to the banner in action:
http://tarkett.mindgrabmedia.com
Yes, in retrospect, doing this in After Effects would probably have been the better tool to use even though some text rendering quality will be sacrificed, but this is so far into it, it would be nice to be able to fix what exists without having to start all over. Plus, I'd really like to move on to something else besides this bloody banner!
Active State To AS2 Button Class (w/Tweener)
Been trying to get my head round this for the past 2days but can't get it to work/
Basically I need to create an active state to a custom button class. I know I need to set a variable to hold the active state onRelease within the class. And also know I need to for loop through all the buttons to de-active any that were previously selected. Think the for loop will go in the main timeline but not sure how to change the states of my button class from the main timeline.
At the mo i'm using Tweeners example here:
http://tweener.googlecode.com/svn/tr...as2_flash8.zip
as a base. Could anyone help with the code to do this? Unfortunatley no forum there!
Problem Making Multidirectional Menu With Tweener Class
hi, currenty im working on my portfolio. and i had the idea to make everything into cubes that i renderd out in 3dmax. so now i have the mainframe and i renderd out an animation in every direction so that when you click on a button the cubes would turn around 90 degres. i also wanted to make an preview, so if the user goes over a button the cubes would turn just a little and if the user leaves the button again the cubes would turn back to normal. i tried to make this like a advanced button. i did made a movieclip with the complete animation of the cubes, and gave instances in the timeline, which i would access then with the the button. but when i go over the button or click on it, nothing happens. i figured that has something to do that the button is accesing other movieclip instances and not his own. so please help me, i searched the inet up and down and couldnt find a solution, please help me im really stuck on this matter for a week now.
heres a picture of the mainframe, with just the cubes that is. there is no button yet.
ande here are some frames of the animation, so that you can see whats going on.
Looking For Tutorial: Custom Cursor That Can Animate And Change On Mousedown?
This seems like it should be fairly simple, but I've had problems figuring it out.
I need to have a custom cursor that the user can control movement of, and on a click it will change.
For instance: say the cursor is a fly swatter. On a click, it appears to swat and can go after and kill movie clip bugs.
I'm just looking for a simple tutorial for one of these types of games that you see everywhere on-line.
Any links would be very helpful!!!
Looking For Tutorial: Custom Cursor That Can Animate And Change On Mousedown?
This seems like it should be fairly simple, but I've had problems figuring it out.
I need to have a custom cursor that the user can control movement of, and on a click it will change.
For instance: say the cursor is a fly swatter. On a click, it appears to swat and can go after and kill movie clip bugs.
I'm just looking for a simple tutorial (break down) for one of these types of games that you see everywhere on-line.
Any links would be very helpful!!!
Animate Things On And Off The Stage Accordingly
The first is a simple .swf that I put together just to see if the actionscript is correct. The second is the corresponding fla file. The third is a larger .fla file of which I applied the same logic, however when I click on any of the buttons in the home state, It either does nothing, goes to the wrong place, or just starts the movie over. I just want to be able to animate things on and off the stage accordingly.
Here is the one that works:
http://red5.ws/testmovies.swf
http://red5.ws/testmovies.fla
Here is the one that does not
http://red5.ws/realdeal2.0.fla
Maybe another set of eyes on this can see something I'm missing
Thanks a ton
Animate Offstage To Stage
hello =].
exactly what the title says.
im trying to get a movieclip from my workarea and animate it onto the stage using AS 3 but i keep getting the error#1009 null blah blah blah.
could anyone give me a few pointers?
my code is very simple:
import fl.transitions.Tween;
import fl.transitions.easing.*;
stage.addEventListener(Event.ENTER_FRAME, intro);
function intro(event:Event):void
{
new Tween(home_mc, "x", Strong.easeOut, menuStart_mc.x, home_mc.x = 30, 6, false);
}
thats the jist of my code...
Stage.width Query : How To Animate The Bg ?
Hi
so i have coded the bg image on the stage so that it fills the screen and resizes with the browser great.
but now i would like to animate that bg. does anyone know the next step in this ? do i need to add more listeners ? if so, to what ? i have a basic .fla i could send any of you if you want to take a look.
thanks, and have a great day
-jt.
Calling SetTimeout Within Custom Class And Cannot Access The Class' Variables
Hi All,
I'm creating an user interface with Flash 8, I'm new to Flash, my background is Java therefore I decided to use ActionScript to create a custom component that is reference within an external file.
My problem I believe is scope related. I have a status bar (label component), once I update the status bar I want to call the
"setTimeout" function to wait a couple of seconds before clearing my status bar. The "setTimeout" function is executing, but for some reason my status bar is not being cleared (accessed).
Below is a snippet of my code. Any help appreciated. Thanks.
/*
External File
*/
import mx.controls.Button;
import mx.controls.Label;
class MyApp
{
//private properties
private var mc_container:MovieClip;
private var btn:Button;
private var lbl_status:Label;
private var str:String = "do see me";
//constructor
public function MyApp(target:MovieClip)
{
trace("-- MyApp --");
mc_container = target.createEmptyMovieClip("mc_container", 100);
}
//public methods
public function init(width:Number, height: Number, xPos:Number, yPos:Number):Void
{
var my_app:MyApp = this;
btn = mc_container.createClassObject(Button, "btn", 1, {label:"click me"});
btn.setSize(100, 25);
btn.move(10, 10);
btn.clickHandler = function():Void
{
trace("btn clicked");
setTimeout(my_app.clearStatus, 2400);
//correct if I call directly
//my_app.clearStatus();
trace(str);
}
lbl_status = mc_container.createClassObject(Label, "lbl_status", 2, {text:"status bar message"});
lbl_status.setSize(200, 25);
lbl_status.move(0, 50);
}
public function clearStatus():Void
{
trace("calling clearStatus");
lbl_status.text = "";
}
}
/*
Called for Flash IDE
*/
var app:MyApp = new MyApp(this);
app.init(200, 200, 0, 0);
[AS3] Making An Auto-generated Class Inherit From Custom Class?
hi, just wondering if this is possible
i was hoping to find a way to get a bunch of objects in my library to inherit from (or even be) one class that i have made, but without having to make .as files for every single one
is this possible, or is there any other way to give objects another classes functionality in an auto-generated class?
cheers
Can't Animate Background Of Button Class
I've made a class that creates a simple button with a label and background. When I rollover the button the background should tween to a color and that's where it's going wrong. It's probably something simple I'm missing but I can't find it.
The text label does tween correctly, but the background doesn't do anything. It also doesn't give any errors when I test it.
ActionScript Code:
package classes
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import gs.TweenFilterLite;
import gs.easing.Circ;
public class NavButton extends Sprite
{
private var _text:String;
private var _background:Sprite;
private var _label:Sprite;
public function NavButton(textLabel:String)
{
_text = textLabel;
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void
{
buttonMode = true;
mouseChildren = false;
addLabel();
drawBackground();
addEventListener(MouseEvent.ROLL_OVER, onOver);
addEventListener(MouseEvent.ROLL_OUT, onOut);
}
private function onOver(e:MouseEvent):void
{
TweenFilterLite.to(_background, 0.2, {tint: 0xfff59b, ease: Circ.easeOut});
TweenFilterLite.to(_label, 0.2, {tint: 0x333333, ease: Circ.easeOut});
}
private function onOut(e:MouseEvent):void
{
TweenFilterLite.to(_background, 0.3, {tint: null, ease: Circ.easeOut});
TweenFilterLite.to(_label, 0.3, {tint: null, ease: Circ.easeOut});
}
private function addLabel():void
{
_label = new Sprite();
var tf:TextField = new TextField();
tf.autoSize = TextFieldAutoSize.LEFT;
tf.selectable = false;
tf.x = 5;
tf.y = 2;
var format:TextFormat = new TextFormat("Arial", 16, 0xffffff, true);
tf.defaultTextFormat = format;
tf.text = _text;
_label.addChild(tf);
addChild(_label);
}
private function drawBackground():void
{
_background = new Sprite();
var w:Number = _label.width + 10;
var h:Number = 24;
_background.graphics.beginFill(0x333333);
_background.graphics.drawRect(0, 0, w, h);
_background.graphics.endFill();
addChildAt(_background, 0);
}
}
}
Tween Class Applied In Custom Class Not Working
var sizerW:Object = new Tween(pda_mc,"_xscale",mx.transitions.Tween.None.e aseNone,pdaOrigW,pdaSmallW,3,true);
this code produces and error when applied in a custom class but not in a fla?
the error = There is no property with the name 'None'.
Custom Transitionmanager Class Problem/class Scope?
I'm writing a class that fades from one scene to another in a video game. A custom transitionManager object is created, and a listener is attached. Once the fade out from one scene is complete, the listener is triggered, the scene switches, and the new scene fades in.
This is the error I'm getting: "There is no method with the name 'myTransitionManager'.
myTransitionManager.addEventListener("allTransitio nsOutDone", fadeListener);". It is given everytime myTransitionManager is accessed by any of the class functions.
I assume this is a class scope issue. How can I create a custom transitionManager object accessable to the entire class? I need it to be accessed by at least three separate class functions.
Here's the source, starting with the constructor for the GameSection class:
Code:
public function GameSection(clip_to_fade:MovieClip){
var myTransitionManager:TransitionManager = new TransitionManager();
}
//class methods
function switch_section(clip_to_fade:MovieClip, fade_in_scene:String) {
// Define a listener object to use with the Tween objects.
var fadeListener:Object = new Object();
//create event listener for transitions being complete
fadeListener.allTransitionsOutDone = function(eventObj:Object) {
trace("allTransitionsOutDone event occurred.");
gotoAndPlay(fade_in_scene);
fadeIn(clip_to_fade);
};
myTransitionManager.addEventListener("allTransitionsOutDone", fadeListener);
fadeOut(clip_to_fade);
}
function fadeIn(in_mc:MovieClip) {
myTransitionManager.start(in_mc, {type:Fade, direction:Transition.IN, duration:1, easing:None.easeNone});
}
function fadeOut(out_mc:MovieClip) {
myTransitionManager.start(out_mc, {type:Fade, direction:Transition.OUT, duration:1, easing:None.easeNone});
}
Thanks!
How Do You Listen In One Class For A Custom Event Dispatched From Another Class?
I am not sure how to word this, so here is what I would like to happen:
MyDocumentClass contains an instance of MyItem and MyItemManager. MyItem will fire an ItemEvent.ITEM_CHANGED event. I want MyItemManager to listen and react to that event. Possible? Here's my code:
ItemEvent.as:
ActionScript Code:
package
{
import flash.events.Event;
public class ItemEvent extends Event
{
public static const ITEM_EVENT:String = "itemEvent";
public function ItemEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false)
{
super(type, true);
}
public override function clone():Event
{
return new ItemEvent(type);
}
public override function toString():String
{
return formatToString("ItemEvent", "type", "bubbles", "cancelable");
}
}
}
MyDocumentClass.as:
ActionScript Code:
package {
import flash.display.Sprite;
import MyItem;
import MyItemManager;
public class MyDocumentClass extends Sprite
{
public var item:MyItem;
public var manager:MyItemManager;
public function MyDocumentClass()
{
item = new MyItem();
manager = new MyItemManager();
item.dispatchCustomEvent();
}
}
}
MyItem.as:
ActionScript Code:
package
{
import flash.display.Sprite;
import flash.events.EventDispatcher;
import ItemEvent;
public class MyItem extends Sprite
{
public function MyItem()
{
}
public function dispatchCustomEvent():void
{
dispatchEvent(new ItemEvent(ItemEvent.ITEM_EVENT));
}
}
}
MyItemManager.as:
ActionScript Code:
package
{
import flash.display.Sprite;
import ItemEvent;
import flash.events.EventDispatcher;
public class MyItemManager extends Sprite
{
public function MyItemManager()
{
addEventListener(ItemEvent.ITEM_EVENT, handleItemEvent);
}
public function handleItemEvent(e:ItemEvent):void
{
// do something here
}
}
}
Applying A Custom Class To An Object In The Document Class...
How's it going guys. I just started learning Actionscript 3.0 and so far not bad. However, I'm having trouble applying custom created classes to objects in the main document class. I'm using Flash as the application, however there is no timeline scripting involved. I loaded the document class called Main.as:
ActionScript Code:
package
{
import flash.display.MovieClip;
import flash.net.URLRequest;
import flash.display.Loader;
public class Main extends MovieClip
{
private var _redBox:Loader = new Loader();
private var _redBoxLink:URLRequest = new URLRequest("images/redbox.jpg");
public var buttonScaleHover:ButtonScaleHover = new ButtonScaleHover();
public function Main()
{
_redBox.x = 100;
_redBox.y = 100;
_redBox.load(_redBoxLink);
addChild(_redBox);
}
}
}
Now, what I'm trying to do is apply this class named ButtonScaleHover.as to the _redBox in the document class. Here is the code for ButtonScaleHover:
ActionScript Code:
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class ButtonScaleHover extends Sprite
{
private var _xScale:Number;
private var _yScale:Number;
public function ButtonScaleHover()
{
trace("The ButtonScaleHover Class is being loaded");
_xScale = this.scaleX
_yScale = this.scaleY
this.addEventListener(MouseEvent.ROLL_OVER, onRollOver);
this.addEventListener(MouseEvent.ROLL_OUT, onRollOut);
}
public function onRollOver(event:MouseEvent):void
{
this.scaleX *= 2;
this.scaleY *= 2;
}
private function onRollOut(event:MouseEvent):void
{
this.scaleX = _xScale;
this.scaleY = _yScale;
}
}
}
I tried using
ActionScript Code:
_redBox.ButtonScaleHover();
in the document class after i added it to the display object list. However, it didn't work. Basically, I'm just trying to apply a custom class to an object(in this case the loader). Thank you guys very much in advance.
Tween Class In Custom Extend MovieClip Class
I want to use the tween prototype in a custom class that extends MovieClip. I am already including "lmc_tween.as" in my root and I have already replaced the "MovieClip.as" file in my flash directory with the one from the shared/Zigo directory. However, I still get compiler errors if I try to include "lmc_tween.as" in the class file, or without the include in the class it will compile but the tween prototype will not work in the custom class. Does anyone know how to fix this?
Applying A Custom Class To An Object In The Document Class...
How's it going guys. I just started learning Actionscript 3.0 and so far not bad. However, I'm having trouble applying custom created classes to objects in the main document class. I'm using Flash as the application, however there is no timeline scripting involved. I loaded the document class called Main.as:
package
{
import flash.display.MovieClip;
import flash.net.URLRequest;
import flash.display.Loader;
public class Main extends MovieClip
{
private var _redBox:Loader = new Loader();
private var _redBoxLink:URLRequest = new URLRequest("images/redbox.jpg");
public var buttonScaleHover:ButtonScaleHover = new ButtonScaleHover();
public function Main()
{
_redBox.x = 100;
_redBox.y = 100;
_redBox.load(_redBoxLink);
addChild(_redBox);
}
}
}
Now, what I'm trying to do is apply this class named ButtonScaleHover.as to the _redBox in the document class. Here is the code for ButtonScaleHover:
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class ButtonScaleHover extends Sprite
{
private var _xScale:Number;
private var _yScale:Number;
public function ButtonScaleHover()
{
trace("The ButtonScaleHover Class is being loaded");
_xScale = this.scaleX
_yScale = this.scaleY
this.addEventListener(MouseEvent.ROLL_OVER, onRollOver);
this.addEventListener(MouseEvent.ROLL_OUT, onRollOut);
}
public function onRollOver(event:MouseEvent):void
{
this.scaleX *= 2;
this.scaleY *= 2;
}
private function onRollOut(event:MouseEvent):void
{
this.scaleX = _xScale;
this.scaleY = _yScale;
}
}
}
I tried using
_redBox.ButtonScaleHover();in the document class after i added it to the display object list. However, it didn't work. Basically, I'm just trying to apply a custom class to an object(in this case the loader). Thank you guys very much in advance.
Doc Class Talks To Custom Class Problems
Hello all,
I am trying to get a Doc class to initiate a function in custom class, but I cant get it to work. I am still very new to working with classes and hope any of you can shine some light onto this problem.
I have 2 MovieClips, one is animating across the the stage via its custom class, and the other is a button control through the Doc class. I want to button to stop the stage.event from animating the first movie across the stage and to rotate the movieclip a value of 20.
So far the movie clip just keeps on going and does not stop.
Here is my Doc Class Code.
Code:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import mcSquare;
import Movesq;
public class MasterMain extends MovieClip
{
private var _square:Movesq;
public function MasterMain ()
{
_square = new mcSquare;
btn.addEventListener(MouseEvent.CLICK, stopBlackSquare, false, 0, true);
btn.buttonMode = true;
}
private function stopBlackSquare():void
{
_square.stopLoop();
}
}
}
Here is the Custom class code ( class name is Movesq)
Code:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.*;
public class Movesq extends MovieClip
{
public function Movesq ()
{
this.addEventListener (Event.ENTER_FRAME, onLoop, false, 0, true);
}
private function onLoop (evt:Event):void
{
this.x +=5;
}
public function stopLoop ():void
{
this.rotation = 20;
this.removeEventListener (Event.ENTER_FRAME, onLoop);
}
}
thank you for your help in advance.
Pending Class OnResult In Custom Class.
Ok,
I have a custom class with private field:
private var test:Stringint the constructor I load the web service:
pws = new WebService(Constants.getWsURL() + "?WSDL");
then I call a method on the WS:
var pcLoadModel = pws.LoadModel();
pcLoadModel.onResult = pcLoadModel_Succ;
pcLoadModel.onFault = pcLoadModel_Fail;
where:
public function pcLoadModel_Succ(result){
//some code.
}
The problem is that where it says "some code", I cant access the members of my class! Why not? in the debugger I clearly see that I have left the scope of the instance of the class I was working from. I dont understand why this happens.
Anyone has an answer to this?
Thanks you :)
Jp
Dynamic Class Reference In Custom Class
I've created a custom class that I want to be able to dynamically insert a movie clip from the library. I'm running into trouble because I want to access the clip as a property of the custom class object (ie: so it can be swapped out for another library clip after instantiation, among other things). I'm using getDefinitionByName() but I can't use it outside my addDiagram() function (see attached code) because the string variable that stores the name of the library clip isn't defined until after the custom class constructor function. Any help is appreciated!
Thanks,
-Erik
Attach Code
public function Panel(panelTitle:String,
panelWidth:Number,
panelHeight:Number,
panelX:Number,
panelY:Number,
panelType:String = "",
panelDisplay:String = ""):void {
this.panelTitle = panelTitle;
this.panelWidth = panelWidth;
this.panelHeight = panelHeight;
this.panelX = panelX;
this.panelY = panelY;
this.panelType = panelType;
this.panelDisplay = panelDisplay;
...
//if panel is to display a diagram, add the diagram clip
protected function addDiagram():void {
var diagramClass:Class = getDefinitionByName(panelDisplay) as Class;
var panelDiagram:* = new diagramClass();
panelDiagram.x = getPanelX() + 5;
panelDiagram.y = getPanelY() + 20;
panelDiagram.scaleX = .95;
panelDiagram.scaleY = .65;
addChild(panelDiagram);
}
Question About Tweener Class From "caurina.transitions.*" Package
For those who are familiar with this package and more specifically the Tweener class within this package, is there a way to add arguments to the "onComplete" function you attach to a tween? e.g.
Code:
Tweener.addTween(some_mc, { x:500, time:1, onComplete: someFunction });
public function someFunction():void {
//some code
}
the above is valid, BUT...is there a way to do this:
Code:
Tweener.addTween(some_mc, { x:500, time:1, onComplete: someFunction(arg1:String, arg2:String) });
public function someFunction(argument1:String, argument2:String):void {
//some code
}
?????????????????????????
if this class doesn't support this, does anyone know of a package or class that does support argument passing after a tween is complete?
thx in advance
Tweener (caurina.transitions.Tweener) In AS3
I dont know If it has been mentioned before but there' s a new version available for download that can be used for be used on AS3 projects targeting Flash Player 9 and above! Check it here: http://code.google.com/p/tweener/
Can I Get The MouseX From One Class's Stage From Inside A Different Class?
I'm working on a first time game using Flash CS3 ActionsScript 3.0 that has a crow class placed on the stage of a main gameStage class. I need to access the mouseX coordinate from the stage of the gameStage class from inside my crow class. I'm attempting to do it via a getter function but seem to be having trouble tracking down the exact proper syntax to avoid errors. Is there any chance I could get an exact syntax example as apposed to hours of online research and study.................8-)
Importing Class To Custom Class
I'm writing my own class. (The Peacock class if you want to know.) I want to use the Tween class in my class, but I don't know how to import another class into my class. How do I go about that. Thanks.
A Custom Class Says My Class Is Null
Hi,
I have a class (Math2) with misc functions for my project. It has a function called CheckRelations() which basically checks a static array in another class (relation). But the Math2 class acts as if the Relation class is non-existent, even though I have imported it and I also have all files in the same folder. When I try to relate to the class in any way i get a Runtime-Error 1009 (Cannot access a property or method of a null object reference.)
I tried tracing the class along with two other classes (one imported, but another is not) the two classes trace fine: [class Human] [class relationship]. The Relation class when traced in the Math2 class results in a 'null'
Code for the CheckRelations function in math2 class: (takes in String value, and returns the index at which the input = relation.Type ( i.e. if (String_Input == Relation.Relations.Type) --> return i ) Return -1 if not found)
------------------------------------------------------------------------------------------------------------------------------
import Human;
import Relation; //notice that Relationship is not imported yet traces out fine
//......REST OF CLASS (other static functions
public static function CheckRelations(relationType:String):int {
///////Variables
trace(Human,Relation,Relationship); //Human and Relationship are classes I used to test problem
//Output: [class Human] null [class Relationship]
var relationType:String;
//relationType: the relation to look for in the relations array
var array:Array = Relation.Relations; //Relations is a public static var (array)
//array: the array to look inside
var relation:Relation;
//relation: used to hold temp values of relations to compare
var ReturnValue:int = -1;
//ReturnValue: the value to return
var i:uint;
//i: used in for..loops
///////Function
//SOURCE OF ERROR: any reference to Relation class
RelationCheck:for (i = 0; i < array.length; i++) {
relation = array as Relation;
if (relation.Type == relationType) { //relation.Type is a string value
ReturnValue = i;
break RelationCheck;
}
}
return ReturnValue;
}
------------------------------------------------------------------------------------------------------------------------------
Code for getRelation function in Relation class:
----------------------------------------------------------------------------------------------------------------------------
public static function getRelation(relation:String):Relation {
var val:int = Math2.CheckRelations(relation); // SOURCE OF ERROR
if (val == -1) {
GameError.InvalidRelation(relation); //throws error when an invalid relation is specified {this is NOT the problem I'm having}
}return Relations[relation];
}
---------------------------------------------------------------------------------------------------------------------------------------------------
Importing Class Into Custom Class
Hi there, I realise I'm not allowed to import classes into other classes but I am not sure how to achieve what I want. I want 2 custom classes to pass data one from another directly. I have 2 custom classes I want to use: one extends the XMLSocket Class:
ActionScript Code:
class Game extends XMLSocket { import XMLParser //not allowed to do this I know! var parser:XMLParser = new XMLParser(); function onXML(src:XML):Void { //trace("xml:"+src); parser.parseIt(src); }}
....and the other is a custom class I want to use to parse XML data that the Game class receives from its XML Socket:
ActionScript Code:
class XMLParser { public function XMLParser() { // constructor } function parseIt(theXML:XML):Void { trace("xmlParser received:"+theXML.toString()); //parsing code goes here }}
As I say I realise I am not allowed to import the parsing class into my Game class (or any class for that matter) but I don't know how to pass data directly between these two classes without referencing them in the main FLA.
If anyone could let me know that would be a massive help, thanks !
Schm
AS3 Custom Component Does Not Appear On Stage
I am trying to create my own custom AS3 component. Figured out just about everything but when it comes time to add it to the stage, it does not show up. The constructor is firing and everything.
*The component source is added to my classpath so it can find the UIComponent class
*The linkage class is BallComp and the base class is MovieClip (tried Sprite also)
*The component's definition has BallComp as its class.
When I replace the import and class inheritance to MovieClip, it works fine.
Here is the custom component's class:
Code:
package {
import fl.core.UIComponent;
public class BallComp extends UIComponent {
//import flash.display.MovieClip;
//public class BallComp extends MovieClip {
function BallComp()
{
trace( this + " created..." );
}
}
}
AS3 Custom Component Does Not Appear On Stage
When I replace the import and class inheritance to MovieClip, it works fine.
Here is the custom component's class:
Attach Code
package {
import fl.core.UIComponent;
public class BallComp extends UIComponent {
//import flash.display.MovieClip;
//public class BallComp extends MovieClip {
function BallComp()
{
trace( this + " created..." );
}
}
}
AS3 Custom Component Does Not Appear On Stage
I am trying to create my own custom AS3 component. Figured out just about everything but when it comes time to add it to the stage, it does not show up. The constructor is firing and everything.
*The component source is added to my classpath so it can find the UIComponent class
*The linkage class is BallComp and the base class is MovieClip (tried Sprite also)
*The component's definition has BallComp as its class.
When I replace the import and class inheritance to MovieClip, it works fine.
Here is the custom component's class:
Code:
package {
import fl.core.UIComponent;
public class BallComp extends UIComponent {
//import flash.display.MovieClip;
//public class BallComp extends MovieClip {
function BallComp()
{
trace( this + " created..." );
}
}
}
Stage.showDefaultContextMenu = False + Custom ContextMenus
I would like to hide the default contextMenu for every displayObject in my application, so I figured i'd use stage.showDefaultContextMenu = false;
however, when i do this, any custom contextMenus I have added fail to appear.
I am adding the custom menus as shown below. Note that these menus appear when i have stage.showDefaultContextMenu = true;
Attach Code
var cmMenu:ContextMenu = new ContextMenu();
var item:ContextMenuItem = new ContextMenuItem("Item 1");
cmMenu.customItems.push(item);
// add a listener if needed, etc ...
sprite.contextMenu = cmMenu;
XML With Custom Class
I am having some difficulties loading XML from an external class. I would like to place the firstChild into a Dynamic Text Box. In my Flash movie the text box is labeled LevelTitle. This is my code at the moment:
Code:
class SelectTest extends XML {
var Testlist: XML;
var curContainer:XMLNode
function SelectTest() {
var Testlist = new XML;
Testlist.load("TestList.xml");
Testlist.ignoreWhite = true;
Testlist.onLoad = getTest()
}
function getTest() {
trace ("success");
var LevelTitle= Testlist.firstChild
trace (LevelTitle);
}
}
It always traces "sucess" leading me to believe that the xml is loading successfully, but when I try to trace LevelTitle, (or Testlist.firstChild, or Testlist.toString()) I always get undefined. What am I doing wrong?
|