I tried to copy a text to clipboard with As3, when I run it on Flash Player it works, but if I include it in a page and I upload it, it doesn' t work.
The code:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("sendTextFromJS", receiveTextFromJS);
function receiveTextFromJS(t:String):void {
System.setClipboard(t);
}
Flash receives the text from JavaScript, but it not insert it in the ClipBoard. Someone knows why?
I guess, Security. FP 10 later securiy changes.
read this article: http://www.adobe.com/devnet/flashplayer/articles/fplayer10_security_changes.html#head31
I recommend. implements using a Clipboard Class
Related
I want to create a re-usable Flash MovieClip (component maybe?) that can be dragged and dropped from the library onto the Flash IDE stage (for an example, a "stop all movieclips timer component").
I've created some attractive vector icon graphics for visual reference, so that when it's dragged onto the stage, the developer can visually see the component on the stage, similar to what Google does with it's DoubleClick components. It's not important for these icon graphics to be seen at runtime however, and I'd like their visual portions to not be compiled at runtime to save on filesize.
I'm often asked to create visually rich Flash units in extremely small file sizes. So basically I want my movieclip icon components to not add to filesize (except for the code portion), not compile and render visually but still have the code within them run.
How can I achieve this? Would creating them as components do anything for my issue? Is this even do-able?
Components are definitely the best way to achieve visually represented imported code, however it would be much easier, more compatible and more reliable to just use an imported code library...
Make a seperate .as file, put it in com/mycompany/animation in your swf folder (or use a global classpath), and add this code:
package com.mycompany.animation {
class MyTimerUtils {
public static function stopAllClipsAfterTime(ms){
setInterval(MyTimerUtils.stopAllClips, ms);
}
public static function stopAllClips(){
//etc
}
}
}
Then when you want to use it in a project, just put this code on frame 1 of your main timeline:
import code.mycompany.animation.MyTimerUtils;
MyTimerUtils.stopAllClipsAfterTime(3000); // 3 seconds
What could be easier? If another developer wants to know if a piece of code is implemented they need only look at the first few lines of code.
I'm working on a Flash project in CS6 and need to import a sound to my library but I'm having endless problems with it. I'm using external files in Actionscript 3.0 (e.g. I cannot do a URLRequest as it won't work externally, need to import)
I'm using a sound that should work, some errors go in that it can't be over 160kbps, this is only at 32 in the MP3 file. I converted it to an AIFF, no success, a WAV? no success.
If it's an MP3 I simply get "Couldn't import "
If it's a AIFF or WAV I get "One or more files were not imported because there was a problem reading them"
Adobe suggest you need to files under 160kbps, all are set at 32kbps to be safe.
Another suggestion said you needed Quicktime 7.7.1 (or newer) and iTunes 10.5.5.3 (or newer) for this to work with an MP3 file. I have Quick 7.7.3 and iTunes 11.0 so I really have no idea of the problem.
Can anyone help, this project needs finished quickly.
Thanks.
John.
Could be to do with bitrates.
I was running into issues with some mp3 files that I had converted from wav using Audacity. It was a specific few that wouldn't work, so I went back to Audacity and compared the working-mp3-yielding wavs to the non-working. I noticed that the working wavs had a bitrate of 44100Hz the non-working had 48000Hz. Setting the project rate ( bottom left corner ) to 44100Hz before exporting yielded mp3s that imported into flash with no problem.
In short:
48000 Hz = naughty
44100 Hz = nice
This is a weird problem here's a simple code snippet that load and play an MP3 sound AS3 doesn't support WAV natively :
//sound object
var sound:Sound = new Sound(new URLRequest("music.mp3"))
var soundChannel:SoundChannel = sound.play();
Hope this help :)
This post is kind of old but I thought I would post an answer after running into the same problem. I am also using Flash Pro in CS6. What you want to do is to embed the sound into your FLA so that when your SWF is compiled the sound will go with it. Khaled's answer is great but this issue needs a little more TLC.
What worked for me was to get an application that edits sound clips. I downloaded the open source 'Audacity.' In the bottom left corner of Audacity you can edit the project rate. Take it down to about 1600 or lower. Then save the project and export the sound as an mp3.
Finally, make sure that your sound clip is in the same folder as your FLA. Import into your FLA (this should work now) and export your sound for actionscript by right clicking the sound in the library, going to properties. Change the name of the class to whatever you want (at least get rid of the '.mp3' from the class name).
Then use the following code (which is different from the typical URL loader for sounds):
//sound is a constructor variable under your document class
public class DocumentClass extends MovieClip
{
var yourSound:yourSoundClass;
public function DocumentClass()
{
init();
}
function init():void
{
yourSound = new yourSoundClass();
}
}
Then play your sound by using yourSound.play(); This technique will embed your sound within the SWF so it will go wherever the SWF goes. I hope that helps anyone who runs into this.
I'm working with the latest version of the SDKs and FlashDevelop. So far, everything about my setup works fine, including external libraries. But when I use GTween, nothing happens. At all. I've tried several of the included samples and some of my own code, and all I get is a blank window or nothing moves, respectively. No errors, but also no action.
Could someone paste in some minimal code that just loads GTween and has it move a sprite? I'd like to have a known good for comparison so I can see if I'm missing something obvious or if there's something weird going on.
Thanks! :)
i just downloaded GTween and copied the com folder to my source...
... this worked fine:
package{
import com.gskinner.motion.GTween;
import flash.display.Sprite;
public class GtTest extends Sprite{
public function GtTest(){
var ball:Sprite = new Sprite();
ball.graphics.beginFill(0xFF0000);
ball.graphics.drawCircle(300,300,10);
addChild(ball);
var myTween:GTween = new GTween(ball, 2, {x:100, y:100}, {swapValues:true});
}
}
}
hope that helps ;)
Are you sure you're compiling to the version of flashplayer you have? It's possible that your player needs to be updated. Hard to tell from this info what could be the problem.
Also GTween is ok, and I have it in one project and used it fairly recently, but there are better alternatives. (gtween was last updated in 2009)
I've been using eaze a lot, but I know most as3-ers flock to TweenLite (for a good reason).
is there any solution on StageWebView.loadURL(), how I can handle URLs in HTML Pages which have target="_blank"?
It's a mobile Android App. (TabbedViewApplication)
Hope someone can help.
Thx
One option is StageWebViewBridge.
StageWebViewBridge is an extended version of flash.media.StageWebView.
Extends loadString method with AS3 - JS communication.
-Extends Bitmap class, you can modify his x,y,alpha,rotation,visible, etc ( Version 1 Beta )
-Communicates Actionscript with Javascript.
-Communicates Javascript with Actionscript.
-Load local files and resources in a easy way.
-Extends loadString method with AS3 - JS communication.
-Extends loadString method to load local resources.
-Lets you take an SnapShot to use as the bitmapData of the bitmap.
StageWebViewBridge source: https://code.google.com/p/stagewebviewbridge/
I never worked with the StageWebView but I know it's really limited. When using an HTMLLoader, you can set a custom HTMLHost instance that specifies to use current HTMLLoader when opening to _blank. However, I don't think it's possible with StageWebView.
public class MyHTMLHost extends HTMLHost
{
public function MyHTMLHost(defaultBehaviors:Boolean=false)
{
super(defaultBehaviors);
}
override public function createWindow(windowCreateOptions:HTMLWindowCreateOptions):HTMLLoader
{
// all JS calls and HREFs to open a new window should use the existing window
return htmlLoader;
}
}
OK, so the only solution for this problem i could found is to load the page (containing the links) as String with the URLLoader and replace its specified parts. Finally loading it via StageWebView.loadString() method.
Problems occur when the Site is dynamic and contains JavaScript. I had also replace some relative links with absolute pathes.
That's it... but I really hope that adobe makes it possible to load those "_blank" links with the StageWebView.loadURL() method.
If you want to capture when a user clicks on a link inside your StageWebView add an an event listener for location changing event (LocationChangeEvent).
This LocationChangeEvent will include the URL they are going to and target. Then you can prevent the URL from loading, let it continue (by doing nothing) or handle it any other way including loading another URL.
If you want to load another URL first stop the loading with stageWebView.stop(). You should also call event.preventDefault(). You can then attempt to
Note: There is another event called locationChange that may be helpful.
As it was declared as an official bug, adobe QA Owner Sanjay C. added a comment: "Able to reproduce the issue with the attached project. Sending to IRB."
So, hope the next Build will come up with the fix wit it.
Best regards
Im looking into using and customizing FLVPlayback in a project. How to go about this is clear, but I noticed 1 anoying thing. When going fullscreen, first Flash player goes fullscreen and then briefly shows the FLVPlayback component in its original size, before jumping to show the video itself fullscreen.
I noticed on Youtube this doesnt happen. How can I escape this 'flicker' and have the video go fullscreen as the videos do on youtube?
Thanks a lot for any tips!
Marcel
in general FLVPlayback along with most of the components built into flash are junk. You are much better off building your own flv player using the NetConnection and NetStream class. Build it once well and generic enough to edit the control visuals and you have yourself a bullet proof flv player for all your projects.
http://actionscriptexamples.com/2008/02/26/loading-flv-files-in-actionscript-30-using-the-netconnection-and-netstream-classes/
Just to say I've used FLVPlayback on jobs many times, and sure it's buggy, but I've never seen this problem. You can definitely fix it. How are you going fullscreen? I've recently being doing something like this...
import flash.display.*;
import flash.events.*;
import fl.video.*;
import flash.geom.Rectangle;
.
.
.
myFLVPlayback.fullScreenTakeOver = false;
mc.stage.fullScreenSourceRect = new Rectangle(0,0,480,360);
myFullScreenButton.addEventListener(MouseEvent.CLICK, onFullScreenButtonClicked);
private function onFullScreenButtonClicked(e:MouseEvent):void {
mc.stage.displayState = StageDisplayState.FULLSCREEN;
}
(though i appreciate you might be using the fullscreen button in an FLVPlayback skin, so this might not be perfect)
NOTE: I just hammered that code in so it might not be perfect/complete. Hopefully you'll find it useful.
++ i'd make sure you set the size and scale of your flvplayback too, e.g. myflvplayback.setSize(w,h)
++ how about myflvplayback.scaleMode = VideoScaleMode.NO_SCALE;