I am using the following code from the Adobe ActionScript guide
(Programming ActionScript 3.0 for Flex):
package {
import flash.display.Sprite;
import flash.media.Sound;
import flash.media.SoundChannel;
public class EmbeddedSoundExample extends Sprite {
[Embed(source="smallSound.mp3")]
public var soundClass:Class;
public function EmbeddedSoundExample() {
var smallSound:Sound = new soundClass() as Sound;
smallSound.play();
}
}
}
The resulting swf refuses to play, tested on two different machines
with two different operating systems (one WinXP desktop, one Zenwalk laptop).
Does anyone have a better example of embedding mp3s using Flex SDK
(i.e. not FlashBuilder or CSx).
Thanks
As it turns out, mxmlc wasn't embedding my assets until I invoked it with the following switch:
-static-link-runtime-shared-libraries=true
After that, the resulting swfs were fine.
I hope this helps someone else using flex SDK / mxmlc.
Related
Thanks very much for being the most answered community on the web.
I have this small problem:
I want to read a database using Tomcat Servlets into a ActionScript DataGrid.
Please mind that I want it to be pure ActionScript; no mix with MXML.
I have already done a exercise with MXML and DataGrid but it is not meeting my requirement.
I want to understand how to use ActionScript libraries.
thanks for listening
Here is the code:
package {
import flash.display.*;
import spark.components.DataGrid;
import mx.collections.ArrayList;
public class EmpDBDebug extends Sprite {
public var empDG:DataGrid;
public var DGArray:Array = [
{Album:'Slanted and Enchanted'},
{Album:'Brighten the Corners'}];
public var DGArrayList:ArrayList;
public function EmpDBDebug() {
empDG = new DataGrid();
DGArrayList = new ArrayList(DGArray);
empDG.dataProvider = DGArrayList;
addChild(empDG);
}
}
}
This is a simplified version of what I want to do. I have replace Servlet with Array. All I want to do is display the DataGrid content on browser. I am not able to do that. It is refreshing but everything is blank. Hope I am doing something wrong. I tried everything. I replace Sprite with Stage but still nothing works.
Since I want to do it in pure ActionScript without using MXML, are there any other libraries which I should be using. And again I am mostly using Notepad++ and MonsterDebugger. I do not have access to fl.data.DataProvider libraries. Let us rule it for the time being. I am bit confused with Flash Licensing. Can I do it with Apache Flex?
Can you throw some light.
thanks again
RR23850
I want to link as3 code to a webpage. I click a button and then go to a web page. I used navigateToUrl. When I compile my fla file then the button is working perfect, going to the required webpage. But without compiling the fla file, when I directly run my swf file, then I cannot go to the required webpage. Why does this happen? Here is my code.
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.navigateToURL;
import flash.net.URLRequest;
link3.addEventListener(MouseEvent.CLICK, WebHyperlink);
link3.buttonMode=true;
function WebHyperlink(e:MouseEvent)
{
var myURL:URLRequest = new URLRequest("http://www.republicofcode.com/");
navigateToURL(myURL, "_blank");
}
You have a security exception because Flash Player blocks internet access to your swf file. To see that exception, you can install a Flash Player debug version from here and to avoid the problem, take a look on my answer for this question.
Hope that can help.
I'm just beginning to get into flash game programming. I know enough to make a functioning project, but not how to make it efficient or do specific tasks, in this case how to add a preloader. I've found several tutorials online, but none that go along with how I've seen is the best method to program. From what I've seen, it is best to program all of my code into one .as file and link this file to the main document. This makes it easy for me to make all of my variables global in scope, which lets me addChild/removeChild in various different functions. The only problem is that I can't find a tutorial on creating a preloader with this method in mind. All tutorials that I've found generally have two frames in the timeline, one with the preloader and one with the content, but I've been told this is not a good way to program. If anyone could help I'd appreciate it a lot. I can paste the source code of one of my learning projects if it would help to provide an answer to my question.
I wouldn't go with the 2 Frame approach. Instead just make your game with your Document Class, like you said you would like to do.
Then when your done, load your compiled game swf into a loader swf.
Here is a simple example on how your loaderSwf should look like:
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
function startLoad()
{
var mLoader:Loader = new Loader();//Or use ProLoader
var mRequest:URLRequest = new URLRequest(“Game.swf”);
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
function onCompleteHandler(loadEvent:Event)
{
addChild(loadEvent.currentTarget.content);
}
function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}
startLoad();
(needs to be wraped in a package and Class if you are using it as Document Class)
I am trying to make IntelliJ IDEA 12 configure rsl libraries for runtime loading.
Do you have any experience with that, and do you maybe have a sample XML you put into aditional compiler options?
Also, I didnt find the plugin for this, if you know any please say
update:
To clarify the practice project more:
I want to make 2 'swf's that will have one tweening library used on a simple shape, but I want to make that tweening library crossdomain rsl.
Then the goal is to in MainApp load and add to stage one swf and then the other. What I expect to happen is that the first time rsl will be loaded and the second time it will be used from cache.
I am programing in pure AS3. Examples would be wonderful :)
Right now I am trying to build one class that has RedSquare and tweening applied to that square. Ofcourse, tweening should come from rsl library.
Update 2:
I got to the point where I create [Frame(factoryClass='path.to.class')] and I create Preloader.
But here now I dont know how to make a preloader that would load rsl's and then go to the next frame, or main class. What [Frame] tag does, is it makes two frames, one for preloader, and one for main class that should be executed after.
Config I pass to the compiler:
<flex-config>
<!-- A list of runtime shared library URLs to be loaded before applications start. -->
<!-- GreenSock -->
<runtime-shared-library-path>
<path-element>/Users/matej/Documents/Projects/Work/External/greensock-as3/greensock.swc</path-element>
<rsl-url>http://localhost/~matej/rsls/greensock.swf</rsl-url>
<policy-file-url>http://localhost/~matej/rsls/crossdomain.xml</policy-file-url>
<rsl-url>http://localhost/rsls/greensock.swf</rsl-url>
<policy-file-url>http://localhost/rsls/crossdomain.xml</policy-file-url>
</runtime-shared-library-path>
<!-- static-link-runtime-shared-libraries: statically link the libraries specified by the -runtime-shared-libraries-path option.-->
<static-link-runtime-shared-libraries>false</static-link-runtime-shared-libraries>
</flex-config>
main class
package {
import com.greensock.TweenLite;
import Preloader;
import flash.display.Sprite;
import flash.events.MouseEvent;
[Frame(factoryClass="Preloader")]
public class RedSquare extends Sprite{
//---------------------------------------------------------------
// Private variables
//---------------------------------------------------------------
private var redRectangle:Sprite;
//---------------------------------------------------------------
// Constructor
//---------------------------------------------------------------
public function RedSquare() {
redRectangle = new Sprite();
redRectangle.graphics.beginFill(0xFFFF0000);
redRectangle.graphics.drawRect(100,100,50,30);
redRectangle.graphics.endFill();
addChild(redRectangle);
redRectangle.addEventListener(MouseEvent.MOUSE_OVER,onOver);
}
//---------------------------------------------------------------
// Public methods
//---------------------------------------------------------------
//---------------------------------------------------------------
// Private methods
//---------------------------------------------------------------
private function onOver(event:MouseEvent):void {
TweenLite.to(redRectangle,3,{x:400,y:200,rotation:160})
}
}
}
This is going to seem quite a lame question - basically we have downloaded a package called Squiggly - http://labs.adobe.com/technologies/squiggly/ - and we are trying to implement it into Flash (using AS3, CS5). And none of us are very good at flash, and have no clue how to do it, the actionscript in the .as is as follows:
package
{
import flash.display.Sprite;
import flashx.textLayout.container.ContainerController;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.conversion.TextConverter;
import flashx.textLayout.edit.EditManager;
import com.adobe.linguistics.spelling.SpellUIForTLF;
public class SquigglyTLFExample extends Sprite
{
public function SquigglyTLFExample()
{
var markup:XML = <TextFlow xmlns='http://ns.adobe.com/textLayout/2008'><p><span>I know </span><span fontStyle='italic'>Enlish</span><span>. Use the context menu to see the suggestions of the missbelled word.</span></p></TextFlow>;
var textFlow:TextFlow = TextConverter.importToFlow(markup, TextConverter.TEXT_LAYOUT_FORMAT);
textFlow.flowComposer.addController(new ContainerController(this, 500, 600));
textFlow.flowComposer.updateAllControllers();
textFlow.interactionManager = new EditManager();
SpellUIForTLF.enableSpelling(textFlow, "en_US");
}
}
}
I have a blank swf, and just want to know how to implement it to a text area. Why do people still use flash? :(
Here's how I got it running in a new FLA file in Flash CS 5:
1) In Flash, go into 'Advanced Actionscript 3.0 Settings' and change to the Librarys path tab on the middle of that pane.
2) Add the AdobeSpellingUITLF.swc.
3) When the SWC has been added, select it in the list and click the little 'I'-icon(when you hover it, it should say: 'Set linkage options for a library').
Change the link type to 'Merged into code'.
4) Add the code you posted (SquigglyTLFExample) as your Document class.
5) Remember to copy the 'AdobeSpellingConfig.xml' and the 'dictionaries'-folder to the same folder as the generated SWF-file.
The configuration in Flash should look something like this:
i have built a class based on squiggle a while ago: http://apdevblog.com/actionscript-spell-checking-with-squiggly-as3-only-and-flash-9-compatible/
it's very easy to use and compatible with normal textfields >flash9.
cheers