Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Animate Something Based On Event



lets say i want to animate something based on the completion of another animation. How do I do that?



Adobe > ActionScript 1 and 2
Posted on: 09/03/2007 10:20:40 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

How To Make The Event Based Block Into Procedure Based
i'd like to do something like this

var a = getXML("xmlfile.xml");

However, the xml component is event based. I only get data when onLoad is fired.

How to wrap this kind of event based function into my custom function?

Event Based Upon Rotation?
Hello.

Is there a clean way to run differing functions based upon the rotation value of a movieclip? I have a menu with 119 drinks on it, all the drinks are shown as strings of text pointing outward from the circumference of a circle. The resulting circle of wines can be rotated, and the user will be provided with additional info as each drink becomes horizontal to the screen.

Is it a case of having an array containing all the relevant info, an event listener listening for the rotation value, and a switch pointing to the correct movieclip to display? Or am I thinking this through ar$e-backwards as usual!

A.

Sound - Stream Or Event Based
what do most ppl use......streaming or once its downloaded? I can tget the timer to work with streaming!

Tracking Event Based Test
Hi:

I am trying to build a test such that we have the user run through several picks and clicks and based on his input we grade the user at the end. So I have some buttons which are supposed to be tracked when clicked etc.. can someone please help me wiith this code..
Thanks

Event Based On Movieclip Instance
Hello!

Bit new to actionscript and need som help from a expert.

I'm trying to add events for specific movieclips. I have a few buttons
on top of a toolbar. The buttons should have unique events and the toolbar
should also have unique events. If I add an event on the toolbar, even though
I press the buttons the toolbar get trigged..I don't want this.
If a button is pressed the toolbar event should not be trigged, only the button.
But if I click the toolbox - where ther isnt a button in front of the toolbox should be trigged.

I guess this is a really simple thing to fix.
Please help



/Adrian

Schedule Based Event Handler
Looking for some advice:

* I need to load in a schedule of events (xml).
* These events are precisely timed (down to a tenth of a second).
* The events (like, attach movie to main screen) need to last for a very precise amount of time (again, within a tenth of a second).

So, it would run like so:
Schedule gets loaded that says:
* "show banana for 15.5 seconds @ 2 min and 32 seconds after the movie started, then remove the banana."
* "show apple for 12 seconds @ 4 min and 12 seconds after the movie started, then remove the apple."

and so on... like 100 of them.

So, what's the best way to handle this? It seems like I'll certainly have to use "setInterval" in there somewhere - but I'm looking for the cleanest and most accurate way to do this.

To complicate things further - my scene is rather computationally intensive (even on the f8 player) and timing accuracy seems to be a weak spot for flash in this kind of situation.

Suggestions?

Change Var Based On Mouse Event
Hi All I hope some one can help with this. I'm new to AS3 so I'm not even sure if I'm taking the right approach. Basically what I want to accomplish is submenu rollover navigation. I can get the main menu to show up and work fine. If I set the var button = 1, 2 ect it pulls the correct section of my XML to display the submenu, but I can't seem to set that var on a mouse_over so when I roll over a different section it changes var.

Hope that makes sense. I also attached my files
Thanks in advance.




PHP Code:



var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
 
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
 
xmlLoader.load(new URLRequest("navigation2.xml"));
 
function LoadXML(e:Event):void  {

xmlData = new XML(e.target.data);

ParseNavigation(xmlData);
ParseMainMenu(xmlData);

}

var mainMenuContainer:Sprite = new Sprite();
var test:int = 1;
var button:int = test;
var submenuContainer:Sprite = new Sprite();
    submenuContainer.x = 142;    
    //trace(mainMenuContainer.miItem);
function ParseMainMenu(mainMenuContent:XML):void {

trace("XML Output");
trace("------------------------");
trace(mainMenuContent.MainMenu.@name);
trace(mainMenuContent.MainMenu.@level);



var MenuList:XMLList = mainMenuContent.MainMenu;
    
    var buttonCount:int = 0
    for each(var prop in MenuList) {
        
        var miItem:mainMenu = new mainMenu();
        miItem.tLabel.text = prop.@name;
        miItem.name = prop.@level; 
        miItem.url = prop.@variable;
        miItem.y = (miItem.height * buttonCount);
        mainMenuContainer.addChild(miItem);
        
        buttonCount++;
    }

}

function ParseNavigation(navInput:XML):void  {

/*trace("XML Output");
trace("------------------------");
trace(navInput.Category.subCat.@name);
trace(navInput.Category.subCat.@level);
trace(subLevel);*/

var subMenuList:XMLList = navInput.MainMenu.subMenu;//.(@sublevel == button);
            
            trace(button);
            var buttonCount:int = 0
    
                for each(var prop in subMenuList) {
                    if (prop.@sublevel == button) {
                        var miItem:MenuItem = new MenuItem();
                        miItem.tLabel.text = prop.@name;
                        miItem.name = prop.@name;
                        miItem.url = prop.@variable;
                        miItem.y = (miItem.height * buttonCount);
                        submenuContainer.addChild(miItem);
                        buttonCount++;
                    }
                }
    
}

addChild(mainMenuContainer);

stop(); 





MenuItem Code As Follows


PHP Code:



var url:String;
this.addEventListener(MouseEvent.MOUSE_UP, gotoURLHandler);
this.addEventListener(MouseEvent.MOUSE_OVER, displaySubmenuHandler);
this.addEventListener(MouseEvent.MOUSE_OUT, removeSubmenuHandler);

function gotoURLHandler(evt:MouseEvent):void {
    
    navigateToURL(new URLRequest(url));
}

function displaySubmenuHandler(event:MouseEvent):void {    
    
    var myRoot:MovieClip = root as MovieClip;
    var myParent:MovieClip = this.parent as MovieClip;
    var button = event.target.name;    
    trace(button);            
                
    this.addChild(myRoot.submenuContainer); // this works for pull the menus in the correct place
   
}

function removeSubmenuHandler(evt:MouseEvent):void {
    var myRoot:MovieClip = root as MovieClip;
    
    //this.removeChild(myRoot.submenuContainer);
}

this.buttonMode = true;
tLabel.mouseEnabled = false; 

Any Ideas? Event Based Pr. Wierdness
http://www.nebulouscore.com/examples...on_class2b.swf

I am working on some event based stuffed which is kinda new to me so maybe someone knows why the bug in this thing happens. The fla is there to if you want to see the code.

When you click the pointer springs to the mc you clicked and calls the next function for all the mc's between the two you click... giving it a sort of traveling effect. BUT it has a tendency to almost randomly highlight an mc as though one of the events got lost on the heap.

That text at the bottom is a sema4 I put in to keep track of the queued tweens and it always returns to 0.

If nothing else, the fit-to-n thing I have going on with the Build_mc_Collection() might be worth borrowing.

Anyway.. I hope you guys might have a clue why this wierdness happens.

The Problem With Event Based Programming
Hi gang,

I have two thread running, the second of which is not getting any response.

ranger class
any ideas? event based pr. wierdness

So.. here is the deal. I am loosing faith in event based programming in flash for reasons mentioned in the second thread. I have no idea what is going on here. The reason I actionscript code the way I do is that I like being in controll and know exactly when something is supposed to execute.

Event based programming has one "flaw" that I find myself searching for workarounds in order to "fit the model". That flaw is that you only get one shot at handling an event. That event certainly can trigger other events but again, this causes one to venture into creative solution to make a series of events happen in "just such a way".

In the above threads, I you can see an example of this thingy I am trying to make where clicking on a menu item makes all the items in between highlight then unhighlight using a tween as it travels the menu items between the previously selected item and the one you just clicked on. (thats a mouthful).

Ideally I would like to call a Next(), which triggers the indexChanged, which starts a tween, calls Next, which triggers the indexChanged.. until the index of Next is equal. BUT! since this event based programming and I have "only shot" I have to get the job done in that one spot.

here is a code snippet


Code:
mcCollection.cursor.setDirection(1);
for(var i=previ;i<newi;i++)
{
mcCollection.cursor.Next(); // triggers onIndexChanged
}
By slamming the "event system" with Next functions, something wierd happens where I suspect the order of events being fired is not the order in which they were called.

In fact, the trace shows:

out:colMC1
in:colMC1
out:colMC2
in:colMC2
out:colMC3
in:colMC3
out:colMC4
in:colMC4
out:colMC5
... sequential throughout until here

out:colMC11
in:colMC11
out:colMC12
in:colMC12
out:colMC13
out:colMC12
in:colMC12

you can see at the end that 12 gets an "extra call".. as though it fired twice. This is just one example of some of the output I have seen from the trace.

anyway.. I just wanted to *****. It's a hobby i guess. Regardless.. event based code is fine for
"when I click this do this"
but gets quircky when
"when I click this, do all this (each of the "all this" is "fire another event").

that sounds muddy I know.. but.. anyway. Frustrated.

Changing Up Event Based On Variable
Is there a way that I can change the color of a button based on a variable in the Flash movie?

I've created the button, I have created Over and Hit events for it, but the Up event needs to be dynamic. So there are one of three options, it could be, say, red, blue or transparent. By default I have it set to transparent, and that works great, but I couldn't find a way to change the color, on load, based on a variable (say if x = 1 then I want the button to be red).

This is bound for a data integration app, but I just need to make sure that it will do what I need it to first.

Thanks in advance for any help. If you can provide code or links to tutorials that might help I would really aprpeciate it.

Brent

Flash Event Based On Computer Clock
Hi.

Is there a way I can get my flash movie to play a different message based on the computers clock?

Good Morning
Good Afternoon
Good Evening

That kind of an idea.

I've seen this question before in forums but can't find the actionscript for it again. I hate that.

Thanx in advance.

Triggering An Event Based On XML <element> Contents.
Hey Gurus:

I am (slowly) learning to use XML with ActionScript 3.0 and have come across something I haven't been able to figure out on my own.

I have two buttons on the stage.

The red button is “button1”.

The orange button is “button2”.

My AS looks like this:


ActionScript Code:
//XML

var myXML:XML = <inventory>
  <slot1>red_square</slot1>
  <slot2>orange_circle</slot2>
</inventory>;

//FUNCTIONS

/*creates a function called addslot
that adds a <slot3> child after <slot2>*/

function addslot() {
    var newSlot:XML = <slot3>green_triangle</slot3>;
    myXML.insertChildAfter(myXML.slot2[0], newSlot);
}

/*creates a function called button1click
that executes addslot(), traces the XML,
then traces the contents of <slot3>*/

function button1click(Event:MouseEvent):void {
    addslot();
    trace(myXML);
    trace(myXML.slot3.text());
}

/*creates a function called sniff that
I want to execute a trace event based
on the contents of <slot3>*/

function sniff() {
    if (myXML.slot3.text()=="green_triangle") {
        trace("slot3 has a green_triangle in it!");
    }
}

//BUTTON LISTENERS

/*adds listeners to both buttons and calls the functions.*/

button1.addEventListener(MouseEvent.CLICK, button1click);
button2.addEventListener(MouseEvent.CLICK, sniff);

M problem is in the function “sniff”. I can't figure out the syntax needed to evaluate the contents of <slot3> and pop a trace based on its contents.

For some effin' reason, I can't attach a ZIP of my source. But, if someone could point me toward a tutorial or give me some sound advice, that'd be stellar.

Thanks,

Andrew444

AS2 Event Based Sound Class (SoundExtended)
I did this a while ago, but I guess I've been digging though my old AS2 to give anyone who needs it a little boost A while ago, ahh... well maybe not too long ago.

I made it because it always p@#$ed me off that the sound object was so crappy in flash. Countless steps to make the sound do what you want in a way a normal person would think of to control a sound. So I added many many new properties and methods, all of which are built over top the original sound object. I kept most of the old methods as well. But now all methods, including getters and setters, fire events, to make controlling the sound a heck of a lot easier. Now muting doesn't just turn the volume down ... well essentially it still does, but I took care of the memory variables in the class. So no more remembering the last volume, or the last play position, etc.,etc... it's all already taken care of in the methods of the class.
A good way to think of this is the Sound controller. But I made this before I ever heard of Model-View-Controller
So...
Let me know what you think, I don't think I have ever really shown this to anyone before. This was actually my first stab at an AS2 class, period.
When you test the source file I should have everything trace to test the events, and the class sould also be commented fairly well.

The example here:
http://www.jimisaacs.com/test/SoundExtended/

The source here:
http://www.jimisaacs.com/test/SoundE...ndExtended.zip

By the way, there's a song in that source file. I'm trusting everyone not to use it for copyright infringement

Actual Time Based Event Idealogy:::
Dear Kings of flash,

I have an idea and need to bring it to life.......

Depending on the time I need to load different flash movies into the main layout. Any ideas or suggestions on how this can be achieved.......??? the brainstorming will greatly help me cause I have a major headache trieng to figure out.......

Cheers

DJ Subandrio
(((((((0)))))))

Can I Control A MovieClip Animation Based On A NetStream Event?
First off, here is the website I'm working on:

http://www.littlefenris.com/RAMPSI/

What I am trying to do is get the animation of the audio levels (red bars next to the power switch) to only happen while a video is actually playing (videos are in the video gallery section). I have the animation done and I can easily get it to start and stop based on pressing the play and stop buttons, but since they start and pause the video you would get instances where the video isn't playing but the audio levels would be animated, which I don't want.

Here is an example of the code in the play button (using NetConnection and NetStream to play the videos):


Code:
play_btn.onPress = function() {
playSound.start();
infoText_txt.text = "PLAY";
my_ns.pause(spotToPlay);
};
The only way I can think to make it work exactly as I want it is to have Flash look to see if the video is actually playing or not and I can't figure out how to do this or if its even possible using the NetStream command I am using to start and stop the videos.

Any help is much appreciated.

Making CUSTOM Functions For Event-based Prog
I understand how to make listeners and use them with existing eventhandlers. Like say using..


Code:
mybutton.onPress=function(){
blah;
}
button.addListener(mybutton);
BUT-

is there a way i can specify the EVENT for a non-established new object? (by that I mean...it's not a button, or text, or key etc.)

I can say "when mybutton is pressed then fire off the event. BUT - Can I say, " Listen for when movieclip1 turns blue ? - then fire off the event? "

thanks...I'm just curious about all the things flash can do.

SoundChannel.position - Trouble Triggering Event Based On .position
I would like to trigger an addChild event when my mp3 reaches a certain point.

My trace statements will only fire if I use <= but not ==

The goal is to add text to the stage when the MP3 has reached one second, what am I missing?

Ultimately there will be several trigger marks I need to hit along the MP3.


ActionScript Code:
var buffer:SoundLoaderContext = new SoundLoaderContext(10000);var welcome:Sound = new Sound(new URLRequest("Intro.mp3"), buffer);var welcomesc:SoundChannel = welcome.play();addEventListener(Event.ENTER_FRAME, playMessage);function playMessage(event:Event):void{trace(Math.floor(welcomesc.position));if (welcomesc.position == 1000)    {        trace("NOW!!!!!!!");    }    else    {        trace("WAIT-------------");    }welcomesc.addEventListener(Event.SOUND_COMPLETE, soundComplete);}

Animate Forward, Animate Backward
This seems like it should be easy, but it's beyond my skill.

I have an animation that I want to play forward when I mouse over, and play backward (to the beginning) when I mouse out. Here's the code:

stop();

function zoomMovie(event:MouseEvent):void
{
play();
}
this.addEventListener(MouseEvent.MOUSE_OVER, zoomMovie);

function mouseOut(event:MouseEvent):void
{
function everyFrame(event:Event):void
{
if (currentFrame == 1)
{
stop();
}
else
{
prevFrame();
}

}
this.addEventListener(Event.ENTER_FRAME, everyFrame);
}
this.addEventListener(MouseEvent.MOUSE_OUT, mouseOut);

Any suggestion are very much appreciated

Noob: Animate, Stop, Animate
basically i'm trying to animate a movie clip from 0 pixel to 550 pixels in x axis, and when i reach 550 pixels in x axis i want it to stop and then animate in y axis from 10 pixels to 100pixels.

how can i do that?

please help me on my problem, it has been bothering me for days.

Frame Based V/s Script Based Animation ?
I guess I'm looking for feedback about your methodoligies for animation. I've been practicing Actionscripting for 3-4 years now and sometimes I get stuck in the thinking that I have to animate everything by scripting the properties of movieclips. I know there are instances were its pointless to script animation or to animate what should be scripted.

What kind of balance if any do you peoples employ when doing a project. I'm working on one right now that I'm scripting out but sometimes I feel like I'm just doing extra work.

Adding Multiple Event Listeners To The ENTER_FRAME Event, Calling Different Functions
Is this going to slow my program down, or do all the references to these functions get added to a master ENTER_FRAME. I am trying to efficiently do this

MovieClipLoader OnLoadInit Event AND Loader Component Complete Event
What´s the difference beetwen the Loader complete event and MovieClipLoader onLoadInit. The manual says onLoadInit is called after the code on the first frame of the loaded clip gets executed, so, it´s better to use onLoadInit if you want to manipulate the loaded asset via code.

So, if anyone could clarify the following points to me, I would be grateful!

- Does the complete event of the Loader component have the same behaviour?
- How does MovieClipLoader knows that the code on the first frame of the loaded assets got executed?

Thanks,

Marcelo.

Custom Event Handlers - Triggering Event Listeners On Other Objects
I'm trying to update an object whenever something happens in another object. At the moment, I have the second object explicitly calling an update function on the first object, but this seems a little sloppy and it strikes me that this is the sort of scenario where I should be using custom event handlers.

I'm not quite sure how they work though. My first assumption is that if I built two objects, one like this which fires off an event:


Code:
public class eventFirer extends Sprite
{

public function eventFirer():void
{
dispatchEvent(new Event("customEvent"));
}
}
...and one like this which updates whenever the custom event happens:


Code:
public class eventListener extends Sprite
{

public function eventListener():void
{
trace ("main");
addEventListener("customEvent", eventFired);
}

private function eventFired(e:Event):void
{
trace ("ok");
}
}
...then eventListener.eventFired would automatically be set off whenever a new eventFirer is created. This seems not to be the case though.

Can anybody enlighten me as to how custom events bubble between otherwise unrelated objects?

Setting Up An Event Listener To Listen For An Event Inside Of Another Movieclip.
I'm trying to set up an event listener on the stage that will listen for a mouseEvent.CLICK on a certain button inside a movieclip on the stage, but i cant seem to figure out how to target that specific button. Any help would be greatly appreciated.

Button Down = Animate In Content - Press Another Button Animate Content Out?
Here's what I am looking for. I want to have my buttons animate my content in and out of my movie stage. I know I can do it using the timeline, but I am looking for a more efficient way of doing it.

If anyone has any advice or any fla's, I would appreciate it.

Thanks
kmaier

Passing Parameters From Event Listener To Event Handler
Hi Chaps,

First of all, apologies as I know this question has been asked before, but I have spent the last twenty minutes reading this thread and still can't seem to figure out how to apply it to my situation - probably because I'm thick!

I have a number of objects which need to be rotated according to different parameters. I have a function which takes those parameters, then uses the tween class to handle the rotation. I'm then using the tweenEvent class to check for when the motion is complete. Then, I need access to those same parameters in the complete handler to do further operations. The problem I have is that the tween event class doesn't allow me to pass the parameters along to the cpmpleteHandler, so I'm stuck getting my parameters from the first function to the second function:


Code:
function rotate(parameters){

rotationTween = new Tween(object,parameter1,parameter2,........);

rotationTween.addEventListener(TweenEvent.MOTION_FINISH,completeHandler);

}

function completeHandler(e:TweenEvent){

//need access to the paremeters passed into the first function here!!

}
From reading the thread mentioned above, I have a feeling I may need a custom class to do this - please don't laugh but I've never written (or had the need to) write my own class before, so I really wouldn't know what to do. Any help greatly appreciated, but an actual code snippet which demonstrates this would be even better!

Ric.

Event Listener Mouse Event Click - Obstructions
This is an oversimplification of my problem.

I have an event listener on a sprite.
I then have portions of this sprite covered with other sprites or moveclips.

If I click a movieclip, it blocks my eventlistener on the sprite underneath it.

Is it possible to listen to the even click 'through' a movieclip. I dont want interaction with them, but I dont want them as bitmap data onto the base sprite either...

I Don't Understand The Keywords: This, Event.target, Event.currentTarget
I am almost a complete beginner to Actionscript 3.0.
I've been looking at tutorials and I now understand most of the basic principles and methods of this programing language (creating basic functions ect..).

However I do not understand the following keywords.

1. this
2. event.target
3. event.currentTarget

What do these words refer to?
How are they different from each-other?
When must i use them?

Event Propagation Vs. Event Blocking -- Confused, Even After Moock
I thought I understood the AS3 event scheme: capture, target, bubbling. That events (e.g. MouseEvents) travel from stage to the object clicked on and then back again, and all objects in the display chain receive and can check that event. But it's also true, it seems, that Interactive Objects in front of others will block and "absorb" events, and those beneath will never hear of the event (unless mouseEnabled for the blocking object is set to false). I don't understand this (seeming) contradiction.

On the Kirupa forums:

Along with event propagation in ActionScript 3 comes different phases of events with display objects. With propagation, you have events being propagated from display objects to other display objects, such as mouse click events being propagated from children to their parents. This lets clicks within children objects to be recognized by parents (since children make up the contents of their parents, its only natural for the parent to also have those same events). The phases of such an event represent the progression of the event as it makes its way through the parent and child objects.

Events actually start with parent objects (phase 1: capturing), starting with the top most parent (stage) and making its way down to the child where the event originated (phase 2: at target). Then after reaching the child it makes its way back up through all the parents again (phase 3: bubbling).

But also:

Though ActionScript 3 now supports event propagation (capturing, bubbling, etc). Events like mouse events still only occur for one specific target for each individual event. In other words, when you click the mouse button over some objects in a Flash movie, only one of those objects is going to recieve the event even though the mouse is physically over other objects as well.…One important thing to keep in mind is that, in ActionScript 3, mouseEnabled is true by default. This means, without any event handlers or listeners used in a movie, every InteractiveObject instance will capture mouse events and prevent them from reaching any other objects beneath them.

Any clarification much appreciated…

Frame Based Easing, Into Time Based Easing (in Actionscript)
i have code to move something from placeA-placeB based on time...then i also have a code to move something from placeA-placeB with easing, but its based on frames...can someone supply me with an easing formula based on time?

The Best Way To Trigger An Event After A Previous Event Has Played.
What would be the best way to trigger an event via button in one movie clip after another event in has played in a different movie clip.

1. Click button in scene 1 on main stage.
2. The background movie (movie2) should scroll the the designated posistion and stop.
3. Then the foreground layer (movie1) should side in over it after the background has scrolled and stop to display information.

Now if you click another button I would like the clip to do this:

1. The foreground layer (movie1) slides back out opposite as it came in.
2. And the the background (movie2) rotates to it's new posistion and stops.
3. The foreground layer slides in same as (movie1) only some other tab and stops.

I'm completely stumped how to do this any help would be greatly appreaciated.

I posted the file here:

http://www.jbowen.com/jbcspage.swf
and
http://www.jbowen.com/jbcspage.fla

If some one could help me out thanks maybe even take a look a the code in the fla document and repost it or explain.

Thanks.

Using An Event Listeners Function At Will - Event Dispatching?
Hi,

I have a event listener that turns a camera on and off according to how much motion there is:


ActionScript Code:
camera1 = Camera.getCamera(""+Number(aCameraComboBoxes[selComboBoxNum].selectedIndex-1));
aCameras[selComboBoxNum].addEventListener(ActivityEvent.ACTIVITY, activityHandler, false, 0, true);

private function activityHandler(event:ActivityEvent):void {
if(event.activating){
//camera is turning on
}else if (!event.activating){
//camera is turning off
}
}

All of this works but I need a way to rerun the addlistener's function without the camera actual turning on or off. Is there a way for me to use this function, and send it the variable it is looking for?

Thanks

Custom Event Handler For A Timer Event?
I understand how to create custom events in order to pass parameters to a function being called by an event listener. I can get this to work fine if the event is being dispatched within my own code. However, I don't get how to do this if the event is a built-in event being dispatched by a Flash object.

Specifically, I need to call a function and pass it parameters when a timer ends. I don't know how to change the information being sent by the Timer because it is a native Flash class rather than something I'm writing. Can someone please clarify how to do this?

Mouse Event, Event.target Vs Movieclip Name
Hi -

Can anyone help me with a mouse event issue, i'm truly baffled. There's a timer event that loads 4 movieclips (named 'serviceType'), each containing an instance of 2 objects (named 'btn' and 'thumbs'). When clicking on the MC (servicetype) it triggers a mouse event. I'm trying to reference child 'thumbs' of the serviceType MC but in the mouse event function, event.target traces no children, but serviceType traces the 2 children. BUT serviceType only refers to the last instance of serviceType that was loaded in the timer event. Why wouldn't event.target work??

Here's the code, and thanks for the help!!

ActionScript Code:
function loadServices(event:TimerEvent):void {
     count = event.target.currentCount -1;
     serviceType = new MovieClip;
     addChild(serviceType);
     btn = new Btn(serviceList, count);
     thumbs = new ThumbContainer(count);
     serviceType.addChild(btn);
     serviceType.addChild(thumbs);
     serviceType.addEventListener(MouseEvent.CLICK,loadThumbs);
}
           
function loadThumbs (event:MouseEvent):void {
     trace(serviceType.numChildren); /// Displays 2 (but refers to the last instance loaded)
     trace(event.target.numChildren);// Displays 0, why??
}

AS 3 Convert Button Event To Key Enter Event
I'm learning how to use regular expressions in ActionScript 3, and can get an input to be tested by regular expressions, and an answer delivered, if a button is clicked after text is entered.

But darn if I can figure how to code it so they just click the enter key after typing what they like. In the following code punk is a button, and there are two text fields, buzzo the input, and tester the answer to the input. The array questo contains the regular expressions, the array anso contains the responses.


I need code to replace the bottom line with a line that relates to key enter being typed. Thanks for any ideas.



Sally










Attach Code

function makeSense(event:MouseEvent):void
{
tester.text="";
var buzz:String = buzzo.text;
buzzo.text="";
for(i=0;i<questo.length;i++){
if(buzz.search(questo[i])!=-1){
tester.text=anso[i];
}
}
}

punk.addEventListener(MouseEvent.CLICK, makeSense);

How To Use SetInterval To Delay Event, Not Just Each Step Of Event
I had some help in setting up this bit of code to fade out a loaded movie:


Code:
function faderFunc() {
_root.holder24._alpha -= 5;
if (_root.holder24._alpha < 0) {
_root.holder24._alpha = 0;
clearInterval(fadeRMS);
}
};
fadeRMS = setInterval(faderFunc, 400);
Trouble is, I am looking to fade the clip slowly to zero once it has been a certain number of seconds, rather than just having the clip fade at a rate of -5 every so many seconds as it is set here.

In comparing this to other code that I have been using setInterval in, I am wondering if the problem is that this setInterval is not control an onEnterFrame event, but rather just control the rate of the alpha fade. I don't see how I could use an on enterFrame with this because the swf has already been loaded into a movie in this same Frame...maybe I am wrong about both of these thoughts, maybe just one.

I would really appreciate some insight on this I have been working with different attempts for a while and cannot get the results I want.

(Here is an example of some other code I am using that does delay the onEnterFrame event, I think, so that the code is not being fully executed until 57 seconds pass...)


Code:
function moveRMS() {
clearInterval(moveRMSInterval);
unloadMovie(_root.holder22);
xstep=(30-holder24._x)/5
ystep =(500-holder24._y)/5
_root.holder24.onEnterFrame = function() {
this._y -= (577-this._y)/ystep;
this._x -= (865-this._x)/xstep;
if (Math.abs(577-this._y)<1 && Math.abs(865-this._x)<1) {
this._y = 577;
this._x = 865;
delete this.onEnterFrame;
}
};
}
moveRMSinterval = setInterval(moveRMS, 57000);

Using An Event Listeners Function At Will - Event Dispatching?
Hi,

I have a event listener that turns a camera on and off according to how much motion there is:

camera1 = Camera.getCamera(""+Number(aCameraComboBoxes[selComboBoxNum].selectedIndex-1));
aCameras[selComboBoxNum].addEventListener(ActivityEvent.ACTIVITY, activityHandler, false, 0, true);

private function activityHandler(event:ActivityEvent):void {
if(event.activating){
//camera is turning on
}else if (!event.activating){
//camera is turning off
}
}

All of this works but I need a way to rerun the addlistener's function without the camera actual turning on or off. Is there a way for me to use this function, and send it the variable it is looking for?

Thanks

How To Use SetInterval To Delay Event, Not Just Each Step Of Event
I had some help in setting up this bit of code to fade out a loaded movie:


Code:
function faderFunc() {
_root.holder24._alpha -= 5;
if (_root.holder24._alpha < 0) {
_root.holder24._alpha = 0;
clearInterval(fadeRMS);
}
};
fadeRMS = setInterval(faderFunc, 400);
Trouble is, I am looking to fade the clip slowly to zero once it has been a certain number of seconds, rather than just having the clip fade at a rate of -5 every so many seconds as it is set here.

In comparing this to other code that I have been using setInterval in, I am wondering if the problem is that this setInterval is not control an onEnterFrame event, but rather just control the rate of the alpha fade. I don't see how I could use an on enterFrame with this because the swf has already been loaded into a movie in this same Frame...maybe I am wrong about both of these thoughts, maybe just one.

I would really appreciate some insight on this I have been working with different attempts for a while and cannot get the results I want.

(Here is an example of some other code I am using that does delay the onEnterFrame event, I think, so that the code is not being fully executed until 57 seconds pass...)


Code:
function moveRMS() {
clearInterval(moveRMSInterval);
unloadMovie(_root.holder22);
xstep=(30-holder24._x)/5
ystep =(500-holder24._y)/5
_root.holder24.onEnterFrame = function() {
this._y -= (577-this._y)/ystep;
this._x -= (865-this._x)/xstep;
if (Math.abs(577-this._y)<1 && Math.abs(865-this._x)<1) {
this._y = 577;
this._x = 865;
delete this.onEnterFrame;
}
};
}
moveRMSinterval = setInterval(moveRMS, 57000);

Using An Event Listeners Function At Will - Event Dispatching?
Hi,

I have a event listener that turns a camera on and off according to how much motion there is:

camera1 = Camera.getCamera(""+Number(aCameraComboBoxes[selComboBoxNum].selectedIndex-1));
aCameras[selComboBoxNum].addEventListener(ActivityEvent.ACTIVITY, activityHandler, false, 0, true);

private function activityHandler(event:ActivityEvent):void {
if(event.activating){
//camera is turning on
}else if (!event.activating){
//camera is turning off
}
}

All of this works but I need a way to rerun the addlistener's function without the camera actual turning on or off. Is there a way for me to use this function, and send it the variable it is looking for?

Thanks

Non-screen-based And Screen-based, I Dont Understand
"If you want to include a preloader (a separate SWF file that loads your primary SWF) with your screen-based document, one way to do this is to create the preloader as a separate SWF file (non-screen-based), and load the SWF file for the screen-based document from within the preloader SWF.

You cannot create a preloader within a screen-based document, because all screens in a document are located on the first frame of the root Timeline, so you cannot call or load other frames."

1st Q. what is a non screen based swf?
2nd Q. what is a screen based swf?
3rd Q. where can i possibly get a preloader code that i can modify?
4th Q. how about the code to load the final movie?
5th Q. can someone explain this to me and the step by step process?

HELP PLEASE!! HELP PLEASE!! HELP PLEASE!! HELP PLEASE!! HELP PLEASE!!

THANK YOU IN ADVANCE GUYS

Using Event.target With An Event Handler
Hi folks,

I'm looking for a more efficient way of doing the following:


Code:
function selectLevel():void{
levelSelect.level1.addEventListener(MouseEvent.MOUSE_DOWN,gotoLevel1);
levelSelect.level2.addEventListener(MouseEvent.MOUSE_DOWN,gotoLevel2);
levelSelect.level3.addEventListener(MouseEvent.MOUSE_DOWN,gotoLevel3);

}


function gotoLevel1(e:MouseEvent):void {

currentLevel = 1;
//load up level 1
}

function gotoLevel2(e:MouseEvent):void {

currentLevel = 2;
//load up level 2
}

function gotoLevel3(e:MouseEvent):void {

currentLevel = 3;
//load up level 3
}
As you can probably see, I have a movie clip called 'levelSelect' which contains three buttons - level1, level2 and level3. What I'm doing so far, is adding an event listener to each button, and then if any of them are clicked, it activates a different event handler function for each button.

However, as the only difference in the handler functions is the number of the level, and then assume I have 100 levels, this doesn't seem like very efficient coding!

So, how can I make it so that I have just a single event handler function which all the buttons use, and get it to recognise which level button was clicked? Effectively, I'm trying to do this:


Code:
function selectLevel():void{
levelSelect.level1.addEventListener(MouseEvent.MOUSE_DOWN,clickHandler);
levelSelect.level2.addEventListener(MouseEvent.MOUSE_DOWN,clickHandler);
levelSelect.level3.addEventListener(MouseEvent.MOUSE_DOWN,clickHandler);

}


function clickHandler(e:MouseEvent):void {

//somehow detect the level number 'n' from the instance name of the button, or the child number of the parent movieclip
currentLevel = 'n';
//load up level 'n'
}
I'm sure it has something to do with e.target, or e.currentTarget, but I can't get further than that!

Cheers,

Ric.

[CS3] Dispatching An Event From Inside An Event
Does anyone know how to dispatch an event from inside another event?

I get crazy! I have tried a hundred ways to dispatch an event from inside a onLoad event when loading a XML-file. It just doesn't work!!

Here is a simple example:

Code:
class myClass {
public var xmlData;

public var addEventListener:Function;
public var removeEventListener:Function;
public var dispatchEvent:Function;

function myClass() {
xmlData = new XML();
EventDispatcher.initialize(this);
}

function loadXML() {
xmlData.onLoad = function(success) {
if(success){
trace("success");
sendEventLoaded();
}
else trace("Error: Xml not loaded");
}
xmlData.load("filename.xml");
xmlData.ignoreWhite = true;
}

public function sendEventLoaded() { // send the Event
trace("sendEventLoaded()");
dispatchEvent({target:this, type:"isLoaded"});
}
}
The first issue is not dispatching the event itself, but calling the function sendEventLoaded(). It's like it can't be found from within the onLoad event. When the onLoad event occurs, the text "success" is traced, and but the text "sendEventLoaded()" is never executed!!

Does anyone know how to call the sendEventLoaded() from within the onLoad event? Or is there any other way to do this?

I'm thankful for any help I can get!!

Event.COMPLETE Or Event.INIT
I'm working with the loader class. I have a SWF that's loading a presentation in another SWF. The loader swf has a progress bar and perecentage text field. I want the presentation to start playing ONLY when it's 100% loaded. As of now, it starts playing at 10 - 11%.

Here's the code:

ActionScript Code:
var swf:String = "ips_test.swf";
var myURL:URLRequest = new URLRequest(swf);
var loader:Loader = new Loader();

loader.contentLoaderInfo.addEventListener(Event.OPEN, initialize);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, inProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completed);
loader.contentLoaderInfo.addEventListener(Event.INIT, initListener);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorListener);
loader.load(myURL);

function initialize(event:Event):void {
   preloader_mc.visible = true;
}
function inProgress(e:ProgressEvent):void {
   var percentage:uint = (e.bytesLoaded/e.bytesTotal)*100;
   preloader_mc.loader_txt.text = percentage.toString() + "%";
   preloader_mc.pbar.scaleX = percentage/100;
}
function completed(event:Event):void {
   if(loader.contentLoaderInfo.bytesLoaded == loader.contentLoaderInfo.bytesTotal) {
     removeEventListener(Event.OPEN, initialize);
     removeEventListener(ProgressEvent.PROGRESS, inProgress);
     addChild(loader);
   }
   preloader_mc.visible = false;
}
function initListener(e:Event):void {
   MovieClip(loader.content).play();
}
function ioErrorListener(e:IOErrorEvent):void {
   preloader_mc.loader_txt.text = "ERROR";
}

Should I start playing the content of the loader on the INIT or COMPLETE function?

EDIT
Please put code in [ as ] [ /as ] tags (without spaces)

Mouse Event Add Event Listener?
sorry, could not think of a better title!
anyway,
I downloaded a class that perfectly works for me,
it's basically a cube that rotates depending on mouse movement,
the way it does it is with the following line:

spBoard.addEventListener(MouseEvent.MOUSE_MOVE,boa rdMove);


what this does is, whenever the mouse moves the cube moves
the boardMove function does the movement based on the mouse's current position

but what i want to do is the keep the cube moving, if the mouse is on its left, it keeps rotating left, and on its rght, keep rotating right...and preferably to have the speed increase/decrease depending on how far/close mouse is to the center of the cube

any suggestions?
firstly is there an event listener that keeps calling the function just for the mouse 'being there' ? i tried rollover, didn't work

or maybe the boardMove function should be modified? i have no idea how though, totally new to AS3, here's the boardMove function for refrence:


ActionScript Code:
private function boardMove(e:MouseEvent):void {
        
                var locX:Number=prevX;
               
               
       
                if(doRotate){
               
               
                prevX=spBoard.mouseX;
                               
               
               
               
                               
                curTheta+=(prevX-locX);
                                   
               
               
                renderView(curTheta);
               
                e.updateAfterEvent();
               
                }
    }

AS3: Event.SOUND_COMPLETE Event Not Firing
hey everyone

have a look at the attached code. its not very complex but for some reason i can't get the onPlaybackComplete method to fire. any ideas why? SoundClick is an mp3 in the library set to export as an extension of the Sound class. it plays fine, so presumably extending Sound and accessing its methods is working ok, just cant get that sound_complete event to fire










Attach Code

package ccg.gui {

import ccg.gui.*;
import flash.events.*;
import flash.media.*;
import flash.utils.*;

public class RiderAudio2 {

private var _effectGenericClick:SoundClick;

public function RiderAudio2 ()
{
trace("RiderAudio INIT");
_effectGenericClick = new SoundClick();
_effectGenericClick.addEventListener( Event.SOUND_COMPLETE, onPlaybackComplete );
_effectGenericClick.play();
};

public function onPlaybackComplete ( e:Event ):void
{
trace("RiderAudio onPlaybackComplete ");
};
};
};

Event Listeners VS Event Functions
I'm working on a new project at work where there's lots of custom objects with lots and lots of event listeners. I keep finding myself saying, "why didn't they just use the built in objects with built in event handling?". However, from what I can see it seems like AS3 leans heavily towards using Event Listeners as opposed to putting event responsibility on the object itself (E.G. XML.onload). Is there an advantage to this (other than making it more Java like?) I've always favoured keeping the responsibility on the object itself because it seems like one less object to keep track of and also makes things feel more self contained. If I have 10 objects that fire 10 different events, I have to create 10 different event handlers (or 10 different case statements within the same event handler), whereas with self event handling, I just code in the event function.

Anyways, I wanted to open discussion to which method of event handling you prefer and why, and also what you believe the advantages to this. I was searching google for previous discussions on this but I couldn't seem to find anything, so I thought I'd get the ball rolling! Looking forward to reading these, try not to be too elitist in your posts!!

Can You Initialize A Function With A Event Also Without Event?
For example i have this function:

function doSomething(event:MouseEvent):void {
trace("do a lot of coding...");
}

Now if i want to run the same function as above without the 'click event' on your mouse that does
not seem to be possible.

Is there a work around? Or is the best way to make a in between function like this:

function doManyThings() {
trace("a lot of code here..");
}

function doSomething(event:MouseEvent):void {
doManyThings();
}

Event Dispatcher: Only Receives Event Once
Hey all,

So I have two classes talking to each other with EventDispatcher. One is a thumbnail of an image, and when it's clicked, it sends an event to the other class to display the full size version. I'm using a MovieClipLoader instance to load the full version (and the thumbnail).

Here's how it's sending the event from the thumbnail class:


Code:

private function initButton () {

this.loadMe.onPress = function () {
this._parent.sendEvent();
}
}

private function sendEvent () {

// create eventObject to be passed to anything that is listening
var eventObject:Object = {target:this, type:'onPhotoSelected'};
eventObject.photo2load = this.photoID;

trace ("send Event " + eventObject.photo2load);

// dispatch event that tells any listeners to load the full version
dispatchEvent(eventObject);

}
And here's what's receiving the event:


Code:
public function onPhotoSelected (listenObj) {
trace ("event received");
this.loadPhoto(listenObj.photo2load);
}

public function loadPhoto (photoID:Number) {

trace ("photoID " + photoID);

fullImageLoader.loadClip(this._parent.fullImageURL + this._parent.fileNames[photoID] + ".jpg", this);

}
The problem I'm having is it loads the full size version ONCE. After that, it no longer receives the event. The ("event received") trace no longer comes through. But the ("send event") trace continues to work.

The other weird part is if I comment out the loadClip, then the events come through just fine on both sides. But it's like after it loads an image once, it quits responding to that event ('onPhotoSelected'). Is there some kind of mis-communication between the events of the MovieClipLoader and my custom event or something?

Any theories appreciated!

Event Handlers Vs. Event Listeners
I'm having trouble understanding why listeners are necessary, beyond tying events to objects "conceptually." Are listeners used that often? What am I missing?

Copyright © 2005-08 www.BigResource.com, All rights reserved