linkage issue(i think) in flash AS3 - actionscript-3

I writing a game in AS3 using flash. The game works, and I'm trying to add music to the game.
I added a mp3 file called Music (linkage Music.mp3)
and I added in the board (which is the whole game ) the following lines
import flash.media.SoundChannel;
public var music:Music;
public var bgmSoundChannel:SoundChannel;
I'm getting error
Type was not found or was not a compile time constant:Music
I had some problems before while trying to use more then one class its seems the my classes doesn't see other classes defined in my fla.
I will be happy to find a solution, and if you know a good explanation about as3 architecture I will be happy to get a link for that as well

The error is because Music is not found as a compile-time class. This is most likely because you have not correctly set its class in the linkage box.
You say its linkage is Music.mp3. This must be Music in order for your code to work.

Related

Controlling Sound / Volume

I added a sound to the Flash Professional CC library and had the program convert it to MP3. If I create a layer and drag-and-drop the sound onto the stage the sound plays fine (even after passing it through Swiffy), however that is all I am able to do so far.
I need some way to control when the sound plays as well as volume. I tried the giving the sound a class (Sound Properties -> ActionScript -> Export for ActionScript and assigned a class name mySound).
Then added this ActionScript to the first frame:
var myAudio:Sound = new mySound();
myAudio.play();
However, after passing it through Swiffy, I get the following errors:
The ActionScript class flash.media.Sound is not supported.
The ActionScript method flash.media.Sound.play() is not supported.
So I can't use the base Sound class in Flash? Is there another base class that can be used and is it compatible with the flash.media.Sound class? Is there some other way to control playback so that it can be played at a specific time -- such as on mouse roll-over or when something is clicked?
You could try using SoundJS. BTW, Flash Pro CC does have an HTML Canvas document type that uses CreateJS (which SoundJS is part of) under the hood. It won't convert AS3 to JS, though, you have to write the JS code yourself.

How do I add a preloader to my game using flashDevelop?

Hi I have made a tile based game using a tutorial from this site http://www.wildbunny.co.uk/blog/2011...m-game-part-1/ My game is complete but I want to add a preloader to it.
A little background for a hopefully better understanding.
FlashDevelop is where all of my as3 files and classes are and I can also test my game here and I works fine.
Flash CS6 is where I have only one scene "scene 1" with one frame on it, this frame has all of my tile based images ( movieClips ) and animations in squares, if I double click a movieClip ( for example "player" ) it will go inside and I have got lots of frames ( jumping, running etc ).
I can't test my game from here, It shows errors (scenes are NAN). I think that's normal not sure - maybe off topic anyway.
I have looked on the internet for a tutorial on preloaders suiting my situation but can't find any using flash with flashDevelop and AS3.
You create a brand new project "Actionscript 3 with preloader", FD will generate you a preloader class *.as file, and a main class file with a [frame] directive in it. Copy the preloader *.as file into your current project, copy the directive from new project's Main.as into your project's Main.as, change the package name if needed in both places (in preloader's getDefinitionByName() call and in the directive - fully qualified class names required), add whatever visuals you want to your preloader class, and you're set.
The directive in my case looked like this:
[Frame(factoryClass="Geologist.Preloader")]
The package is Geologist, and the startup() function of the preloader was like this:
private function startup():void
{
var mainClass:Class = getDefinitionByName("Geologist.Main") as Class;
var theStage:Stage = this.stage;
theStage.addChild(new mainClass() as DisplayObject);
theStage.removeChild(this);
}

Internal AS3 preloader & stage issues

I need to create a single SWF with no external files, so I'm trying to add an internal preloader to my Flash project which has [embed] assets. I know [embed] causes problems with preloaders because it puts the assets on frame 1. I have tried the solutions recommended in these posts, where you set the document class to your preloader class:
Preloader for SWF with embed bytearray
How to create Preloader in AS3
I can get it to work, but ONLY if I comment out any lines of code that involve the stage, otherwise I get an "Error #1009: Cannot access a property or method of a null object reference." Those lines are essential though, so does anyone know how to fix those errors with the stage?
You haven't posted your code or your fla, so all I can do is share what works for me.
First, I wouldn't use Embed. Instead, use a swc. I have found that Embed can be unreliable as far as actually getting the entire asset in there (at least when publishing with Flash Builder + Flash Pro, which is my workflow).
Once you have your assets in a swc, try the following steps:
Set your export frame to Frame 10 (or any frame other than 1--I like frame 10 because then you can read the label that says "Preloader")
Put your actual content on frame 11. You can structure this a lot of ways. Since I program to Interfaces, I give whatever is on frame 11 an instance name and then use a setter to determine that my "first thing" has been placed on stage. I can get away with this because my main Document Class just knows the definition of the Interface, not the full implementation of the Class, so the Class does not need to load for the main Document Class to work. You probably aren't truly using the timeline and probably didn't program to interfaces, so you'll probably just set the base class of the symbol that's on frame 11 to the main logic of whatever you're trying to do.
Put your preloader graphics in Frame 1. I'm not sure why your stage references are so important. I, personally, don't use any logic in the preloader. Instead, I use a spinner that spans frames 1-10 (plus the word "Loading...". The spinner just spins while the classes load. The embed frame acts as a temporary "stop" that just holds the timeline back until those classes have been loaded. Once the classes have been loaded, the timeline will act like you called play() on it. So it really can be that simple. If you need it to be more complicated, give one of your preloader graphics an instance name and set up a getter/setter pair for it, then use the setter to trigger your logic that accesses the stage. You are pretty much guaranteed to have a valid stage at that point.
Word of warning: if you did make use of the timelime, you will get strange results if you try to jump to a frame that isn't loaded yet, so make sure to check to see if a given frame is loaded if it's near the end of your main timeline and your main timeline is heavy with assets before calling goToAndPlay() or goToAndStop().
Some references that might help you further:
Preloaders vs as 3 (I'd recommend you read the entire series this is part of. This is an amazing series I wish I'd found 3 years ago)
Solving the Frame 2 Problem Presentation and code
Combining the Timeline with OOP The example code for that is here (long story)

AS3 Starling: Trying to add Video

I'm a total AS3 / Starling newbie, but I'm trying to (programmatically) add an FLV video file to the 'background' of what is essentially a splash screen.
Example code I have found online basically distills to...
var v:Video = new Video(100, 100);
this.addChild(v);
This works in the top-level class that extends flash.display.Sprite, however my Game class (that extends starling.display.Spite) fails, complaining of an "Implicit coercion of a value of type Video to an unrelated type DisplayObject."
Strangely enough, the signature of the addChild function on the Starling Sprite class is the same as that of the Flash Sprite class.
So basically the question is: why do I seem to be unable to add a Video object as a child to a Starling Sprite class (but successfully to a Flash Sprite class)?
I'm sure the answer is ridiculously simple... please let me know if I need to add more code or anything. Or if what I'm doing is totally the wrong way.
Or you could add the video to the Flash layer which sits above Starling:
Starling.current.nativeOverlay.addChild(v);
and
Starling.current.nativeOverlay.removeChild(v);
Bare in mind you are not using Starling GPU drawing with this though.
This is because the Starling framework was designed to mimic the regular Flash DisplayList (not completely recreating all the features though). Concretely, you are trying to pass a reference to an object of type starling.display.DisplayObject instead of flash.display.DisplayObject, which gives the appropriate error.
In order to play a video with Starling, you could upload each frame of the movie to a texture. Have a look at this topic on Starling's forum.

Flash AS3 error when importing 3D-tweened movieclip

I've been working on an AS3 application and it's nearing completion. At the same time, one of the designers I work with has been building a movieclip in a separate .fla that acts as an intro animation to the application. The intro uses the 3D motion tweening capabilities of Flash CS4 / Player 10, and runs fine in the .fla in which it was built.
The problem is that when I import the movieclip into the main .fla for the application, when I dynamically instantiate the movieclip and add it to the stage, I get a barrage of the following runtime error:
ReferenceError: Error #1069: Property null not found on fl.motion.KeyframeBase and there is no default value.
at fl.motion::KeyframeBase/getValue()
at fl.motion::MotionBase/getValue()
at fl.motion::Animator3D/setTime3D()
at fl.motion::AnimatorBase/set time()
at fl.motion::AnimatorBase$/processCurrentFrame()
at fl.motion::AnimatorBase$/parentEnterFrameHandler()
I'm guessing just based on the number of errors like this that I receive that there's one per keyframe in the tweening movieclip. I've checked to ensure that the Flash publish settings are identical across the two .fla files, and although the stage sizes differ slightly, I don't think that's the issue here. I've also googled the issue and found nothing but but this lonely thread on kirupa.
Any thoughts?
Okay--turns out the problem was that we had a local version of the fl.motion package in the Actionscript source paths that was out of date. Now everything's tweening along happily!
As far as I know you once you apply a 3D Motion Tween to a clip, you can no longer modify it by actionscript.
I'd suggest either copying the clip, without the tween, so you can access and modify it via actionscript, as for the animation, maybe go for Copy Motion as Actionscript 3.0. It will spit out a nasty looking bulk of code. The alternative is to 'redo' the animation using something like TweenLite which has nicer syntax. You would select the motion tween, give it an instance then use instance.motion.keyframes to loop through the keyframes and get the position and rotation values for example.
It's not as ideal as it should be :(
Have a look at the flashthusiast.com website for more insights on the new tweens and how to work with them.
Goodluck,
George