Problem disabling audio after dragging and dropping as3 - mute

I made three pictures pulled to stick with three others, and it was done successfully.
I wanted to add a reinforcement sound if the attachment was pulled and attached correctly, and another voice indicates dissatisfaction when the operation is not successful,
Problem: Booster still works on all images after a one-time success, and failure sound does not work.
That is, I was not able to correctly formulate symbols that control sounds from inside the library to work.
Please help solve the problem
In the code:
Names of images being pulled (r1, r2, r3), names of still images (m1, m2, m3), the sound of success mus1 and the sound of failure mus2
////////////////
stop();
r1.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);
function fl_ClickToDrag(event:MouseEvent):void
{
r1.startDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
function fl_ReleaseToDrop(event:MouseEvent):void
{
r1.stopDrag();
if(r1.hitTestObject(m1))
{
r1.x=m1.x
r1.y=m1.y
}
else
{
r1.x=30.05
r1.y=155.95
}
}
r2.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2);
function fl_ClickToDrag_2(event:MouseEvent):void
{
r2.startDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_2);
function fl_ReleaseToDrop_2(event:MouseEvent):void
{
r2.stopDrag();
if(r2.hitTestObject(m2))
{
r2.x=m2.x
r2.y=m2.y
///////////////Sound code for reinforcement
var musAPlay:Ahsant = new Ahsant();
var musA1Channel:SoundChannel = new SoundChannel();
SoundMixer.stopAll();
musA1Channel.stop();
musA1Channel = musAPlay.play();
}
else
{
r2.x=30.05
r2.y=249.4
//////////////Sound code not being successful
var musBPlay:noah = new noah();
var musB1Channel:SoundChannel = new SoundChannel();
SoundMixer.stopAll();
musB1Channel.stop();
musB1Channel = musBPlay.play();
}
}
r3.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_3);
function fl_ClickToDrag_3(event:MouseEvent):void
{
r3.startDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_3);
function fl_ReleaseToDrop_3(event:MouseEvent):void
{
r3.stopDrag();
if(r3.hitTestObject(m3))
{
r3.x=m3.x
r3.y=m3.y
}
else
{
r3.x=30.05
r3.y=347.4
}
if(r1.hitTestObject(m1)&& r2.hitTestObject(m2) && r3.hitTestObject(m3))
gotoAndPlay (5)
}
//////////////////////////

I was able to solve the problem by replacing the stage with the name of the button, and after the code for the sound indicating for success, I put the following:
button.removeEventListener(MouseEvent.MOUSE_DOWN, fl_ReleaseToDrop);
button.removeEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
Where button is replaced with the custom name according to work

Related

How do I destroy and recreate a graph with tooltips in anti/G6?

I create a graph using Antv/G6, and this graph has tooltips. It works properly. However, if I destroy and recreate the graph (see code below), the graph redisplays, but the tooltips are no longer displaying. Any idea would be greatly appreciated as I am currently at a loss for ideas.
if (endpointsGraphCreated) {
endpointsGraph.destroy();
}
endpointsGraph = new G6.Graph(endpointConfiguration); // ERROR
endpointsGraphCreated = true;
// This element must be mounted before creating the graph
const data = { nodes: gNodes, edges: gEdges.slice(0) };
// endpointsGraph.data(data);
endpointsGraph.read(data); // combines data and render
}
I was misusing destroy(). I should be using clear() instead and make sure to not recreate the graph. The following works as expected:
if (endpointsGraphCreated) {
// removes all nodes and edges. Leaves configuration intact
endpointsGraph.clear();
} else {
endpointsGraph = new G6.Graph(endpointConfiguration); // ERROR
endpointsGraphCreated = true;
}

How to refresh Factbox

I have a form, when i click on my button.It adds to my table A (what my factbox shows)is it possible to refresh the factbox with X++ code? I can't figure out how to refresh my infopart or query which factbox uses.
For an infopart you can call an update of the data source of the infopart's form run:
void clicked()
{
PartList partList;
int i;
FormRun infoPartFormRun;
FormDataSource infoPartDataSource;
super();
partList = new PartList(element);
for (i = 1; i <= partList.partCount(); i++)
{
infoPartFormRun = partList.getPartById(i);
if (infoPartFormRun.name() == identifierStr(MyInfoPart))
{
infoPartDataSource = infoPartFormRun.dataSource();
if (infoPartDataSource)
{
infoPartDataSource.research();
}
}
}
}
I added the check for the infoPartDataSource because I first tested this with a cue group fact box, which does not have a data source (or at least I could not figure out how to get the data source of one of the cues in the cue group and since you asked for an infopart fact box, I did not investigate further).
Update: The issue seems to be popular at the moment, Martin DrĂ¡b also wrote in his blog about it: Refreshing form parts

Flex Async Madness - Any way to wait for a rpc.Responder to get a response before going to the next statement?

I feel like I must be doing this wrong. I've got a function that is supposed to construct a query based on an API's description of available fields. Here's what I've got:
var query_fields = getQueryFieldsFor(sobject_name);
// Need query fields for the next statement, which actually does the query
public function getQueryFieldsFor(sObject:String):String{
//helper function to get queryfields for given sobject
var queryFields:String = '';
app.connection.describeSObject(sObject,
new mx.rpc.Responder(
function(result:DescribeSObjectResult):void{
var returnFields:String = '';
for ( var field:Field in result.fields ){
if(field.active){
returnFields.concat(field.name+',')
}
}
returnFields.slice(0, returnFields.length-1); //remove last comma
queryFields = returnFields;
}, function(error):void{
Alert.show('error in getQueryFieldsFor function');
})
);
return queryFields;
}
I know this doesn't work, and I think I understand why. However, I keep running into this type of issue and I believe I'm just thinking about it/designing it wrong. So what's a better pattern here? Would really appreciate any insight on this. Many thanks in advance.
It would be better to externalize your functions and execute your next line of code after the fact:
public function getQueryFieldsFor(sObject:String):String
{
var responder:Responder = new Responder( onResult, onFault);
app.connection.describeSObject(sObject, responder);
}
private function onResult(result:DescribeSObjectResult):void
{
var returnFields:String = '';
for ( var field:Field in result.fields ){
if(field.active){
returnFields.concat(field.name+',')
}
}
returnFields.slice(0, returnFields.length-1); //remove last comma
queryFields = returnFields;
}
Your main problem though is not the code, but a lack of thinking asynchronously. You cannot have a function called "getQueryFields" that will return it instantly. What you want to do is think in the request/response way. You're trying to get some data, a request is made to a service, gets the data back, updates a property which is then binded to a view which gets redrawn. This is the proper way to do any webapp.
It might be beneficial for you to also look at application frameworks like RobotLegs and Parsley since it helps you manage these situations. Parsley also has a task library which lets you perform several asynchronous task one after another.

Multiple TrackingParticipants not working, have funny side effects?

We are rying to use WF with multiple tracking participants which essentially listen to different queries - one for activity states, one for custom tracknig records which are a subclass of CustomTrackingRecord.
The problem is that we can use both TrackingParticipants indivisually, but not together - we never get our subclass from CustomTrackingRecord but A CustomTrackingRecord.
If I put bopth queries into one TrackingParticipant and then handle everythign in one, both work perfectly (which indicates teh error is not where we throw them).
The code in question for the combined one is:
public WorkflowServiceTrackingParticipant ()
{
this.TrackingProfile = new TrackingProfile()
{
ActivityDefinitionId = "*",
ImplementationVisibility = ImplementationVisibility.All,
Name = "WorkflowServiceTrackingProfile",
Queries = {
new CustomTrackingQuery() { Name = "*", ActivityName = "*" },
new ActivityStateQuery() {
States = {
ActivityStates.Canceled,
ActivityStates.Closed,
ActivityStates.Executing,
ActivityStates.Faulted
}
},
}
};
}
When using two TrackingParticipants we have two TrackingProfile (with different names) that each have one of the queries.
in the track method, when using both separate, the lines:
protected override void Track(TrackingRecord record, TimeSpan timeout)
{
Console.WriteLine("*** ActivityTracking: " + record.GetType());
if (record is ActivityBasedTrackingRecord)
{
System.Diagnostics.Debugger.Break();
}
never result in the debugger hitting, when using only the one to track our CustomTrackingRecord subclass (ActivityBasedTrackingRecord) then it works.
Anyone else knows about this? For now we have combined both TrackingParticipants into one, but this has the bad side effect that we can not dynamically expand the logging possibilities, which we would love to. Is this a known issue with WWF somewhere?
Version used: 4.0 Sp1 Feature Update 1.
I guess I encounterad the exact same problem.
This problem occurs due to the restrictions of the extension mechanism. There can be only one instance per extension type per workflow instance (according to Microsoft's documentation). Interesting enough though, one can add multiple instances of the same type to one workflow's extensions which - in case of TrackingParticipant derivates - causes weird behavior, because only one of their tracking profiles is used for all participants of the respective type, but all their overrides of the Track method are getting invoked.
There is a (imho) ugly workaround to this: derive a new participant class from TrackingParticipant for each task (task1, task2, logging ...)
Regards,
Jacob
I think that this problem isn't caused by extension mechanism, since DerivedParticipant 1 and DerivedParticipant 2 are not the same type(WF internals just use polymorphism on the base class).
I was running on the same issue, my Derived1 was tracking records that weren't described in its profile.
Derived1.TrackingProfile.Name was "Foo" and Derived2.TrackingProfile.Name was null
I changed the name from null to "Bar" and it worked as expected.
Here is a WF internal reference code, describing how is the Profile selected
// System.Activities.Tracking.RuntimeTrackingProfile.RuntimeTrackingProfileCache
public RuntimeTrackingProfile GetRuntimeTrackingProfile(TrackingProfile profile, Activity rootElement)
{
RuntimeTrackingProfile runtimeTrackingProfile = null;
HybridCollection<RuntimeTrackingProfile> hybridCollection = null;
lock (this.cache)
{
if (!this.cache.TryGetValue(rootElement, out hybridCollection))
{
runtimeTrackingProfile = new RuntimeTrackingProfile(profile, rootElement);
hybridCollection = new HybridCollection<RuntimeTrackingProfile>();
hybridCollection.Add(runtimeTrackingProfile);
this.cache.Add(rootElement, hybridCollection);
}
else
{
ReadOnlyCollection<RuntimeTrackingProfile> readOnlyCollection = hybridCollection.AsReadOnly();
foreach (RuntimeTrackingProfile current in readOnlyCollection)
{
if (string.CompareOrdinal(profile.Name, current.associatedProfile.Name) == 0 && string.CompareOrdinal(profile.ActivityDefinitionId, current.associatedProfile.ActivityDefinitionId) == 0)
{
runtimeTrackingProfile = current;
break;
}
}
if (runtimeTrackingProfile == null)
{
runtimeTrackingProfile = new RuntimeTrackingProfile(profile, rootElement);
hybridCollection.Add(runtimeTrackingProfile);
}
}
}
return runtimeTrackingProfile;
}

How to automatically refresh a web-page using ASP.NET?

I have an asp.net application that would 'simulate' real-time video. I did that acquiring multiple picture from an mysql database.
The problem is how would it be displayed on the web-page.? I refresh the page 1 second per picture, the result is the pictures are choppy and flickery.
Response.AppendHeader("Refresh", "1")
How can I make the refresh rate of the page 4times per second? or is there any implementation for it to be displayed in a continent way.
I would really appreciate if you will reply. good day (^_^)...
here is the script that i am using to read the images from the database,.
If dr.Read Then
dr.Read()
Response.ContentType = "image/jpeg" 'gets or sets the type of output stream
Response.BinaryWrite(dr.Item("file")) 'writes a stream of binary characters to the
http output stream
Else
Response.Write("There is no current active webccast.")
End If
dr.Close()
create a javascript method to change the image using xmlhttpobject and recursively set a timer
function Timer() {
setTimeout("getImage(['imageContainer1'])", 200);
t = setTimeout("Timer()", 100);
}
function getImage(params) {
var request=getXMLhttpObject();
makeRequest("ajax/ObtainImage.aspx?name='myimage'+param[1]+'.jpg",request, imageResponseHandler(request, params));
}
function getXMLhttpObject() {
return (navigator.appName == "Microsoft Internet Explorer")? new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
}
function makeRequest(url,request, Handler) {
request.open("GET", url, true);
request.onreadystatechange = Handler;
request.send(null);
}
function imageResponseHandler(request,params) {
return function() {
if (request.readyState == 4)
document.getElementById(params[0]).src = request.responseText;
}
}
I would either use some Javascript/Ajax to change the content or the meta-refresh (probally not the best for fast refresh).
Maybe you need to think about loading more than one picture onto the page and using javascript to cycle between them. Rather than refreshing the page you could get the pictures using AJAX.
If you really want to simulate video, you need to be able to display at least 15 pictures each second (15fps). Making that many requests per second isn't a great idea.
If you absolutely must do this, I'd suggest "buffering" the pictures first, before displaying them, and if possible, fetching them in batches:
buffer = [] // cache loaded images
bufferSize = 30 // load 30 images before playing
function loadImage(src) {
var img = new Image()
img.src = src
buffer.push(img)
}
function animate(target) {
if (buffer.length > 0) {
var img = buffer.shift()
document.getElementById(target).src = img.src
}
}
function bufferImages() {
for (var i=0; i<bufferSize; i++) {
loadImage('/ajax/ObtainImage.aspx?name=img')
}
}
setInterval("animate('imgTarget')", 65) // should give us about 15fps
setInterval("bufferImages()", 1000) // every second
Add this to the head of your html document.
Not the most efficient way, but it will work.
<meta http-equiv="refresh" content=".25" />

Resources