I'm testing Adobe AIR with flex, and I wanted to play a mp3 via an open file dialog, I did that :
import flash.filesystem.*;
import flash.events.Event;
import flash.media.*;
import mx.core.SoundAsset;
public var loadedFile:File;
public var channel:SoundChannel;
public var song:SoundAsset;
private function loadFile():void {
loadedFile = new File();
loadedFile.browseForOpen("Open multimedia File");
loadedFile.addEventListener(Event.SELECT, fileSelected);
}
private function fileSelected(event:Event):void {
song = new SoundAsset()
song.load(URLRequest(loadedFile.url));
channel = song.play();
}
But when I try to open a file, after the Open file dialog close, I get this error :
TypeError: Error #1034: Type Coercion failed: cannot convert "file:///C:/Users/Kedare/Music/05-Scene%20V%20~%20Prelude.mp3" to flash.net.URLRequest.
I can't find anything related to that on Google or another documentation, all the docs I find is related to play a sound using URL and not Local files :(
Any idea of what can be the problem ? What can I do ?
Thank you !
Change
song.load(URLRequest(loadedFile.url));
to
song.load(new URLRequest(loadedFile.url));
Related
I tried to implement the method 2 of sharing a BLE connection. Whatever I tried, it's not compiling. I'm new to Java, Android, BLE, RX etc., so I'm lost without help.
Here is an excerpt of my code:
import com.jakewharton.rx3.ReplayingShare;
import com.polidea.rxandroidble2.RxBleClient;
import com.polidea.rxandroidble2.RxBleConnection;
import com.polidea.rxandroidble2.RxBleDevice;
:
public class sbrBTSupport
{
:
private Observable<RxBleConnection> connectionObservable;
:
RxBleDevice bleDevice = bleClient.getBleDevice (sbrMAC);
connectionObservable = bleDevice.establishConnection (false).compose (ReplayingShare.instance ());
ReplayingShare is providing an object while an Observable<RxBleConnection> is needed.
I found suggestions in many posts here, but nothing worked. Please indicate where do I have to write what differently.
Thanks
Dieter
I have a requirement where in I need to download couple of files (done using karate feature file) and move them to a specific folder (done using java and calling it in the feature file).
In between that I need to check if all the expected files are downloaded. So what I was thinking is, if there is a way to generate report before moving them to the specific folder. So from the report I can come to know if it has passed or failed.
I have the code for generating cucumber report in the runner class and i tried to use the below in the feature file and it does not run.. Gives an error
* def report = Java.type('BI.BiTestRunner')
* def result3 = report.generateReport()
Error:
BI.BiTestRunner failed due to: Arity error - expected: 1 actual: 0
Code in my runner class
package BI;
import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.ReportBuilder;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static org.junit.Assert.assertTrue;
public class BiTestRunner {
#Test
public void testParallel() {
System.setProperty("karate.env", "BI");
Results results = Runner.path("classpath:BI/Fluent.feature").outputCucumberJson(true).tags("~#ignore").parallel(1);
generateReport(results.getReportDir());
assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
}
public static void generateReport(String karateOutputPath) {
Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[]{"json"}, true);
List<String> jsonPaths = new ArrayList(jsonFiles.size());
jsonFiles.forEach(file -> jsonPaths.add(file.getAbsolutePath()));
Configuration config = new Configuration(new File("target"), "qa-automation");
ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
reportBuilder.generateReports();
}
}
Can someone help me on this please?
No, you can't do this. Until Karate completes, the files needed for generateReport() will not even exist.
This will require some advanced Java - and you can refer the section in this guide with the title "Retry Framework".
With some custom Java code you should be able to take any failed tests at the end of a Runner invocation and re-try them, and merge the results back into the final aggregated report. See example code.
If the above does not help, please consider this as not supported by Karate.
#Vishnuprya k I know this is a pretty old topic, but I managed to make the generateReport working as expected (generating Cucumber report before test method run ends).
Below is my code:
Test.class
public class AllTestsRunnerTest {
#Test
void testAll() {
Results results = Karate.run().relativeTo(getClass()).tags("~#ignore").outputCucumberJson(true).parallel(1);
generateReport(results.getReportDir());
assertEquals(0, results.getFailCount(), "Expected failures");
}
public static void generateReport(String karateOutputPath) {
Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[] { "json" }, true);
List<String> jsonPaths = new ArrayList<>(jsonFiles.size());
jsonFiles.forEach(file -> jsonPaths.add(file.getAbsolutePath()));
Configuration config = new Configuration(new File("target"), "Your project name here");
ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
reportBuilder.generateReports();
}
}
pom.xml
<dependencies>
<!-- Functional / UI / API -->
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit5</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<!-- Reporting -->
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Note: In my feature files I do not have the def report and def result3 directives set.
Hope this helps!
Basically, irrespective of what changes I make to my source, compiling alway yields either a transcoding error, or a missing definition.
I'm new to flash so it's difficult for me to understand how to go about fixing the problem.
Anyway here is the source.
The stack overflow link I always put in all my source, to look at for encouragement every time I feel like banging my head against the keyboard.
// Main.as
package
{
// General imports
// http://stackoverflow.com/questions/564756/should-i-just-give-up-on-programming
import com.bit101.components.Label;
import flash.display.*;
import flash.events.*;
import AssetManager;
// Begin external facing class
public class Main extends Sprite
{
public function Main()
{
var globalFont:String = AssetManager.FONT_PFRONDA;
//var myLabel:com.bit101.components.Label = new Label(Main = null, xpos = 25, ypos = 30, text = "Test Successfull");
//addChild(myLabel);
}
}
---
// AssetManager.as
package
{
public class AssetManager
{
[Embed(source = 'C:\\Documents and Settings\\Geko\\Desktop\\Flash\\testclient\\lib\\MinimalComps_0_9_5_\\src\\assets\\pf_ronda_seven.ttf', fontName = 'PF Ronda Seven', fontWeight = 'normal', advancedAntiAliasing = 'true', mimeType = 'application/x-font-truetype')] public static const FONT_PFRONDA:String;
}
}
Currently when I try to compile I get the following error...
C:\Documents and Settings\Geko\Desktop\Flash\testclient\src\Main.as(6): col: 31
Error: Definition com.bit101.components:Label could not be found.
and if I remove the comment from "var myLabel" or "addChild lines" in Main.as, then I get..
C:\Documents and Settings\Geko\Desktop\Flash\testclient\lib\MinimalComps_0_9_5_\src\com\bit101\components\Component.as(51): col: 4: Error: transcoding parameter 'embedAsCFF' is not supported by 'flex2.compiler.media.FontTranscoder'
C:\Documents and Settings\Geko\Desktop\Flash\testclient\lib\MinimalComps_0_9_5_\src\com\bit101\components\Component.as(51): col: 4: Error: Unable to transcode /assets/pf_ronda_seven.ttf.
My classpaths are "src", "lib\MinimalComps_0_9_5_\src\assets", and "lib\MinimalComps_0_9_5_\src\com\bit101\components"
I'm using Flex SDK 3.5.0.12683 on Windows XP with FlashDevelop 3.2.1 RTM
Any ideas as to why I'm constantly receiving errors each time I try to build the project?
C:\Documents and Settings\Geko\Desktop\Flash\testclient\src\Main.as(6): col: 31 Error: Definition com.bit101.components:Label could not be found.
this would suggest that the application can't find the Label class, possible reasons could be a problem with your classes library path, not importing the Label class, problem with the Label class package name etc...
The other two errors have to do with the way your font is embed. "embedAsCFF" requires Flex SDK 4.
In the error message you get a mention to the flex2 compiler.
'flex2.compiler.media.FontTranscoder'
Are you sure to be using the Flex SDK 3.5? I don't use FlashDevelop myself , so I wouldn't know where to look in order to edit the current Flex SDK.
How to save a string into file (file.superlongextention) in applicationdirectory and get its real locationon Hard drive (like C:/files/...)?
For security reason you can't write into the Application directory (for testing you can but it 's realy not recommended).
You can write into the Application Storage directory to store your application data.
Use File then FileStream to write your data.
To get the path of the file use nativePath.
import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.filesystem.FileMode;
import mx.controls.Alert;
// get a file reference to the storage directory
var file:File=File.applicationStorageDirectory.resolvePath("myfile.withextension");
// create a file stream
var fs:FileStream=new FileStream();
// open the stream for writting
fs.open(file, FileMode.WRITE);
// write the string data down to the file
fs.writeUTFBytes("my string to save");
// ok close the file stream
fs.close();
// show the path to the file we have saved using Alert
Alert.show(file.nativePath);
but you can save file in Applicationdirectory
var appPath:File = File.applicationDirectory.resolvePath("");
var fromUserPath:File = File.userDirectory.resolvePath(appPath.nativePath);
Thanks to Tanel Teemusk
http://blog.teemusk.com/2011/10/writing-to-applicationdirectory-with-adobe-air/
I think you can help me out from this little problem.
I am a novice in Facebook developer by choosing ActionScript 3 as my developer platform. I use SWC library from official facebook-actionscript-api that promoted by Adobe.
So I followed their tutorial. So I did following instruction:
Create Flex project.
Download and put Facebook_library_v3.4_flex.swc to \lib in Flex project.
Provide following code:
import com.facebook.Facebook;
import com.facebook.utils.FacebookSessionUtil;
private var fbook:Facebook;
private var session: FacebookSessionUtil;
protected var api_key : String = "my-facebook-app-api-key";
protected var secret_key : String = "my-facebook-app-secret-key";
public function init() : void {
//fbook = new Facebook();
session=new FacebookSessionUtil(api_key,secret_key,this.loaderInfo);
var fbook : Facebook = session.facebook;
session.validateLogin();
}
After trying to run debug session. I got the error after execute this statement:
session=new FacebookSessionUtil(api_key,secret_key,this.loaderInfo);
I think I did something wrong but I couldn't figure it out. Could you help me by giving your advice or any guideline?
This is exception I got:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.facebook.utils::FacebookSessionUtil()[C:\Users\MikeHunt\Work\FacebookAPI\src\com\facebook\utils\FacebookSessionUtil.as:128]
at CheeseZaa/init()[/Users/teerasej/Documents/Flex Builder 3?/freelance/CheeseZaa/src/CheeseZaa.mxml:24]
at CheeseZaa/___CheeseZaa_Application1_creationComplete()[/Users/teerasej/Documents/Flex Builder 3?/freelance/CheeseZaa/src/CheeseZaa.mxml:4]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9440]
at mx.core::UIComponent/set initialized()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1168]
at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:718]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8744]
at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8684]
I notice that the first line of exception show this:
com.facebook.utils::FacebookSessionUtil()[C:\Users\MikeHunt\Work\FacebookAPI\src\com\facebook\utils\FacebookSessionUtil.as:128]
But I don't sure it involve in exception.
My development platform is:
Macbook Pro
OSX Snow Leopard 10.6
Flash Player 10.0.32 Debugger
Mozilla Firefox 3.6
Flex builder 3.2
Flex SDK 3.5
Facebook_library_v3.4_flex.swc
Every suggestion and guideline would be thank you. I think this would be good for other developer that may found the same problem like me.
loaderInfo is not ready and is currently null.
try:-
public function init():void
{
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true);
}
private function onAddedToStage(event:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
session = new FacebookSessionUtil(api_key, secret_key, this.loaderInfo);
var fbook:Facebook = session.facebook;
session.validateLogin();
}