I am trying to get this to work for ages but doesnt seem to work out quite well
this is my code:
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
var cola:Loader;
cola = new Loader()
cola.load(new URLRequest("resources/colabar.swf"));
this.addChild(cola);
//cola.currentLabel = "frame1";
This works. The .swf is in my stage now. Moving from frame to frame.
Obiously, when deleting the // its not working. And ill get this error message: 1119: Access of possibly undefined property currentLabel through a reference with static type flash.display:Loader.
Try this:
cola.contentLoaderInfo.addEventListener(Event.COMPLETE, colaCompleteHandler);
...
function colaCompleteHandler(event:Event):void
{
var loader:Loader = LoaderInfo(event.target).loader;
var mc:MovieClip = loader.content as MovieClip;
if (mc) {
mc.gotoAndPlay("frame1");
}
}
i.e. wait for the SWF to load, then set the label.
Related
I've executed my code in selenium-java and i need a value of Identifiers(2nd line, not the 4th one) from .XML which is opened in MS edge browser.
My XML:
<Application Type="ABCD">
<Identifier>18753</Identifier>
<SalesChannel SalesChannelType="PQRS" SalesChannelSegment="XYZ">
<Identifier>AB1234</Identifier>
Can anyone help me with the code to get a values(18753) which is between Identifier 2nd line.
Note: I've a code which is working fine for chrome & FF, but bot able to work for MSedge:
Assert.assertTrue(driver.getPageSource().contains("Identifier"));
String xml = driver.getPageSource();
String appID = xml.split("<Identifier>")[0].split("</Identifier>")[1];
I think there's a mistake in your split function. The right code should be like this:
String appID = xml.split("</Identifier>")[0].split("<Identifier>")[1];
Sample code:
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
public class Edgeauto {
public static void main(String[] args) {
System.setProperty("webdriver.edge.driver", "your_path_of_webdriver\\msedgedriver.exe");
EdgeOptions edgeOptions = new EdgeOptions();
WebDriver driver = new EdgeDriver(edgeOptions);
driver.get("http://xxx.xml");
Assert.assertTrue(driver.getPageSource().contains("Identifier"));
String xml = driver.getPageSource();
String appID = xml.split("</Identifier>")[0].split("<Identifier>")[1];
System.out.println(appID);
}
}
Result:
I have to create an mscons export of energy values. I created a bit of code from some examples I found, but now I stuck. MSCONS needs an UNB and an UNH header.
I can add the UNB header to the UNEdifactInterchange41 object, but I don't find a method to attach the UNH header.
Here's my code so far:
import org.milyn.SmooksException;
import org.milyn.edi.unedifact.d16b.D16BInterchangeFactory;
import org.milyn.edi.unedifact.d16b.MSCONS.*;
import org.milyn.smooks.edi.unedifact.model.r41.*;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.StringWriter;
import org.milyn.smooks.edi.unedifact.model.r41.types.MessageIdentifier;
import org.milyn.smooks.edi.unedifact.model.r41.types.Party;
import org.milyn.smooks.edi.unedifact.model.r41.types.SyntaxIdentifier;
public class EDI {
public static void main(String[] args) throws IOException, SAXException, SmooksException {
D16BInterchangeFactory factory = D16BInterchangeFactory.getInstance();
UNEdifactInterchange41 edi = new UNEdifactInterchange41();
Mscons mscons = new Mscons();
/*UNB*/
UNB41 unb = new UNB41();
unb.setSender(null);
Party sender = new Party();
sender.setInternalId(getSenderInternalId());
sender.setCodeQualifier(getSenderCodeQualifier());
sender.setId(getSenderId());
SyntaxIdentifier si=new SyntaxIdentifier();
si.setVersionNum("3");
si.setId("UNOC");
unb.setSyntaxIdentifier(si);
unb.setSender(sender);
edi.setInterchangeHeader(unb);
/*UNH*/
UNH41 unh = new UNH41();
MessageIdentifier mi=new MessageIdentifier();
mi.setTypeSubFunctionId("MSCONS");
mi.setControllingAgencyCode("UN");
mi.setAssociationAssignedCode("2.2h");
String refno=createRefNo();
unh.setMessageIdentifier(mi);
/* How to attach UNH? */
}
}
Sounds like you got it almost right, you need to attach the UNH to message and not the opposite:
mi.setMessageIdentifier(unh);
You have an example there if you need:
https://github.com/ClaudePlos/VOrders/blob/master/src/main/java/pl/vo/integration/edifact/EdifactExportPricat.java
I've had a great deal of success using the DevGirl XpenseIt solution offered by Jason Sturges in response to a couple of other requests for help with this: (http://stackoverflow.com/questions/11812807/take-photo-using-adobe-builder-flex-for-ios being the best example)
Great success except that between the time you press the 'Use' button in iOS6 after taking a photo using the CameraUI and the util class from the tutorial, it takes fully 47 1-hippopotamus, 2 hippapotamusses until the 'fileReady' event occurs.
It doesn't seem, to my mind that it should take the Loader class that terribly long.
Is there something I can do to improve this performance? I'm forced to add a hurry-up-and-wait UI element so my users won't think the program has hung. Here's the code of the CameraUtil.as from the above as I'm currently using it.
// http://stackoverflow.com/questions/11812807/take-photo-using-adobe-builder-flex-for-ios
package classes
{
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.events.MediaEvent;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.media.CameraRoll;
import flash.media.CameraUI;
import flash.media.MediaPromise;
import flash.media.MediaType;
import flash.utils.ByteArray;
import mx.graphics.codec.JPEGEncoder;
import events.CameraEvent;
[Event(name = "fileReady", type = "events.CameraEvent")]
public class CameraUtil extends EventDispatcher
{
protected var camera:CameraUI;
protected var loader:Loader;
public var file:File;
public function CameraUtil(target:IEventDispatcher=null)
{
super(target);
if (CameraUI.isSupported)
{
camera = new CameraUI();
camera.addEventListener(MediaEvent.COMPLETE, mediaEventComplete);
}
} // End CONSTRUCTOR CameraUtil
public function takePicture():void
{
if (camera)
camera.launch(MediaType.IMAGE);
} // End FUNCTION takePicture
protected function mediaEventComplete(event:MediaEvent):void
{
var mediaPromise:MediaPromise = event.data;
if (mediaPromise.file == null)
{
// For iOS we need to load with a Loader first
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleted);
loader.loadFilePromise(mediaPromise);
return;
}
else
{
// Android we can just dispatch the event that it's complete
file = new File(mediaPromise.file.url);
dispatchEvent(new CameraEvent(CameraEvent.FILE_READY, file));
}
} // End FUNCTION mediaEventComplete
protected function loaderCompleted(event:Event):void
{
var loaderInfo:LoaderInfo = event.target as LoaderInfo;
if (CameraRoll.supportsAddBitmapData)
{
var bitmapData:BitmapData = new BitmapData(loaderInfo.width, loaderInfo.height);
bitmapData.draw(loaderInfo.loader);
file = File.applicationStorageDirectory.resolvePath("receipt" + new Date().time + ".jpg");
var stream:FileStream = new FileStream()
stream.open(file, FileMode.WRITE);
var j:JPEGEncoder = new JPEGEncoder();
var bytes:ByteArray = j.encode(bitmapData);
stream.writeBytes(bytes, 0, bytes.bytesAvailable);
stream.close();
dispatchEvent(new CameraEvent(CameraEvent.FILE_READY, file));
}
} // End FUNCTION loaderComplete
} // End CLASS CameraUtil
} // End PACKAGE classes
I was able to solve my delay problem by removing a step from the process. This step is one I myself do not need (at the present time) but others may, so removing it is not really an answer to the question of 'why does this process that seems reasonable take what seems an unreasonable amount of time.
I needed the BitmapData, not an external file so instead of:
Camera => [snap] => Media Promise => Loader => Write File => Event => Read File => Use BitmapData
I rewrote the class to cut out the File/AppStorage i/o.
Camera => [snap] => Media Promise => Loader => Use BitmapData
and so a very reasonable (and expected amount of comp time).
I am still surprised however that it takes such a long time to write the data to a file using the method used in the CameraUtil class. I do need to write these images out to files, but not until the user has reduced the size to a 1024x768 crop area and I encode them into a very compressed jpg, so hopefully I'll only struggle with a smaller portion of the hang/comp time.
Anybody know... Should it take so very long to write 1 file to application storage in iOS from Adobe AIR (via flex)?
I found this process painstakingly slow, too ...
However, it seems the JPEGEncoder is contributing a lot to this delay.
You can speed up the process a lot using the optimized Encoder that can be found here.
http://www.bytearray.org/?p=775
Depending on your device it is about 2 to 4 times faster than the original one.
Another step that can be omitted is the bitmapData.draw(), which is slow as well, by using the Loader.content directly. This way you skip the instantiation of another bitmap instance, which will blowup memory usage.
Like this:
protected function loaderCompleted(event:Event):void
{
var loader:Loader = (event.target as LoaderInfo).loader;
var bitmap:Bitmap = loader.content as Bitmap;
(...)
}
Still, I'm waiting for somebody to write an iOS .ane which should be able to encode a jpg in a few ms instead of seconds. But in the meantime... ;)
So I am trying to store and load data but for somereason I get error code 1046 - type was not found or was not a comile-time constant and 1120 - access of undefined property SharedObject.
I have imported the right files needed.
This code is in a frame on a timeline and should run once the person clicks on the page that is corresponding with the code.
Code:
import flash.desktop.NativeApplication;
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.setInterval;
// Listen for exiting event.
NativeApplication.nativeApplication.addEventListener(Event.EXITING, onExit);
// Also save every 30 seconds.
setInterval(save, 30*1000);
// Load data.
load();
function onExit(e:Event):void
{
save();
}
function save():void
{
// Get the shared object.
var so:SharedObject = SharedObject.getLocal("myApp");
// Update the age variable.
so.data['age'] = int(so.data['age']) + 1;
// And flush our changes.
so.flush();
// Also, indicate the value for debugging.
trace("Saved generation " + so.data['age']);
}
function load():void
{
// Get the shared object.
var so:SharedObject = SharedObject.getLocal("myApp");
// And indicate the value for debugging.
trace("Loaded generation " + so.data['age']);
}
As usual, this error means you haven't imported the class definition. Add this to the import section of your AS file:
import flash.net.SharedObject;
Hi i have looked up a lot of answers but havnt been able to fix my problem. I am using external actionscript and i have used the following code:
package
{
import flash.display.MovieClip;
import flash.net.*;
import flash.events.*;
import flash.display.Loader;
import fl.motion.MotionEvent;
import flash.ui.Mouse;
public class submenu1 extends MovieClip
{
private var movieLoader:Loader;
//everything in this function is exicuted when you start the application
public function submenu1()
{
movieLoader = new Loader();
image3_btn.addEventListener(MouseEvent.MOUSE_DOWN,addMovie);
image4_btn.addEventListener(MouseEvent.MOUSE_DOWN,addMovie);
exit_btn.addEventListener(MouseEvent.MOUSE_DOWN,closeTheMovie);
}
private function addMovie(e:MouseEvent)
{
if(e.target.name=="image3_btn")
{
loadTheMovie("image3");
}
else if(e.target.name=="image4_btn")
{
loadTheMovie("image4");
}
}
private function loadTheMovie(m:String)
{
var movieRequest:URLRequest = new URLRequest("../swf/" + m + ".swf");
movieLoader.load(movieRequest);
addChild(movieLoader);
}
private function closeTheMovie (e:MouseEvent)
{
removeChild(movieLoader);
exit_btn.addEventListener(MouseEvent.MOUSE_DOWN,closeTheMovie);
}
}
}
I can get the sub movie to open but i cant get the exit_btn to close the sub movie and return to the original. I am wanting the exit_btn when clicked to remove the child and take you back to the texture page. The flash itself doesn't bring up any errors just the button wont work. Any suggestions?
Did you export to actions script your exit buttons? Right click on the exit button then choose properties and then click on the box called export for actionScript.